Hi,
I am inserting records into an sqLite table. I am using REPLACE rather than insert as I have a primary key constraint. Before I do the insert I check if there as records in the target table with primary keys that match the ones I wish to insert. I do this so I can flag the records in the target table as being replaced rather than original.
I search for each primary key in the target if the key exists I Put the value in a "duplicates" map. The key and value I put in each map entry are the same; double value (the julian date/time)
So my duplicates map ends up with:
Key Value
2458790.55902778 2458790.55902778
2458790.5625 2458790.5625
...
When I do the REPLACE query I check whether the primary key field value is in the duplicates map and if it is I enter the DateTime ticks into the "conflictPrimKey" field of the table otherwise I enter Null into this field.
The parameters to be inserted in the query are held in a List called aggListArg.
List Item 0 => row(0) = 2458790.55902778
List Item 1 => row(0) = 2458790.5625
If I use the following code valid keys are not found:
If I use this code it works fine
I wonder what I'm doing wrong.
When you look at row(0) and the map key/values in the debugger they appear identical yet looking for the row(0) value in the map doesn't work.
I have attached a little program that demo's this issue.
Any ideas?
Best regards
Rob
I am inserting records into an sqLite table. I am using REPLACE rather than insert as I have a primary key constraint. Before I do the insert I check if there as records in the target table with primary keys that match the ones I wish to insert. I do this so I can flag the records in the target table as being replaced rather than original.
I search for each primary key in the target if the key exists I Put the value in a "duplicates" map. The key and value I put in each map entry are the same; double value (the julian date/time)
So my duplicates map ends up with:
Key Value
2458790.55902778 2458790.55902778
2458790.5625 2458790.5625
...
When I do the REPLACE query I check whether the primary key field value is in the duplicates map and if it is I enter the DateTime ticks into the "conflictPrimKey" field of the table otherwise I enter Null into this field.
The parameters to be inserted in the query are held in a List called aggListArg.
List Item 0 => row(0) = 2458790.55902778
List Item 1 => row(0) = 2458790.5625
If I use the following code valid keys are not found:
This never finds keys in the map:
If duplicates.ContainsKey(row(0)) Then
ArgArray.Add(batchNo)
Else
ArgArray.Add(Null)
End If
If I use this code it works fine
This works:
Dim primaryKey As Double = row(0)
If duplicates.ContainsKey(primaryKey) Then
ArgArray.Add(batchNo)
Else
ArgArray.Add(Null)
End If
I wonder what I'm doing wrong.
When you look at row(0) and the map key/values in the debugger they appear identical yet looking for the row(0) value in the map doesn't work.
I have attached a little program that demo's this issue.
Test Program:
Sub AppStart (Args() As String)
Dim duplicates As Map
duplicates.Initialize
Dim aggListArg As List
aggListArg.Initialize
duplicates.Put(2458790.55902778, 2458790.55902778)
duplicates.Put(2458790.5625, 2458790.5625)
aggListArg.Add(2458790.55902778)
aggListArg.Add(2458790.5625)
For Each row As String In aggListArg
Dim primaryKey As Double = row
Log(" ")
Log("Using intermediate variable - primaryKey")
If duplicates.ContainsKey(primaryKey) Then
Log(" Add Batch No - Correct")
Else
Log(" Add Null - Incorrect")
End If
Log("Using row value")
If duplicates.ContainsKey(row) Then
Log(" Add Batch No - Correct")
Else
Log(" Add Null - Incorrect")
End If
Next
StartMessageLoop
End Sub
Log Output:
Waiting for debugger to connect...
Program started.
Using intermediate variable - primaryKey
Add Batch No - Correct
Using row value
Add Null - Incorrect
Using intermediate variable - primaryKey
Add Batch No - Correct
Using row value
Add Null - Incorrect
Any ideas?
Best regards
Rob