Android Question DBRequestManager problem passing null uniqueidentifier to SQL Server

Frank Cazabon

Member
Licensed User
Longtime User
I am using DBRequestManager to send data from a SQLite database on my tablet to a SQL Server on a Windows server. My code is failing with this error:

java.sql.SQLException: Conversion failed when converting from a character string to uniqueidentifier.

The error occurs when I try to send a Null value to a uniqueidentifier field that is set to allow nulls.

This should work, shouldn't it? Or do I need to do something special with Nulls in order to pass them?
 

Frank Cazabon

Member
Licensed User
Longtime User
Hmm... with some more investigation it seems that the expected value is "null" not null! This would explain the error, but why would a null get stored as a character string in SQLite?

The code that I use to populate the sqlite table is this:

B4X:
    Dim dispositionPK As String
    If chkDelivered.Checked = False Then
        dispositionPK = dispositionMap.Get(spnDisposition.SelectedItem)
    Else
        dispositionPK = Null
    End If
   
    m.Put("del_dspfk", dispositionPK)

    DBUtils.InsertMaps(SQLLite, "DeliveryHistory", ListOfMaps)

How can I add a null value in? Should I change the code to this instead?

B4X:
    Dim dispositionPK As String
    If chkDelivered.Checked = False Then
        dispositionPK = dispositionMap.Get(spnDisposition.SelectedItem)
        m.Put("del_dspfk", dispositionPK)
    End If
   
    DBUtils.InsertMaps(SQLLite, "DeliveryHistory", ListOfMaps)
 
Upvote 0

keirS

Well-Known Member
Licensed User
Longtime User
I suspect the problem is in DBUtils not dealing with nulls correctly. Try building your own string and use ExecNonQuery and use the SQLite NULL keyword.

B4X:
Dim sInsertSring As String
sInsertSring = 'INSERT INTO DeliveryHistory (del_dspfk) VALUES (NULL)'
 
Upvote 0

Frank Cazabon

Member
Licensed User
Longtime User
Thanks, changing my code where I just don't issue a Put on the map for this key works.

I suspect doing this would also work:

B4X:
m.Put("del_dspfk", Null)

As I have code similar to that elsewhere, but maybe there is a problem with DBUtils converting a variable with a null value, or maybe there's something wrong with my code assigning the Null value to the variable.
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hello, someone can tell me that Oedipus to Get to the field of type "uniqueidentifier"
sField = aRecord.GetDouble ("UniqueField")
thanks
 
Upvote 0

Roberto P.

Well-Known Member
Licensed User
Longtime User
Hello,
I just solved:

if the data type uniqueidentifier to read data from the DB to use:

aCursor.GetString ("FieldName")
I hope it is useful to others
 
Upvote 0
Top