B4J Question SQLlite - dbutils problem

hakha4

Member
Licensed User
Longtime User
Just started with SQLlite and B4J and I have problems getting the hang of it. If I understand things right you can't use ordinary SQL commands like 'SQLExecute' ?

I'm starting building sub's for searching,inserting data etc but problems. From error I expect 'ExecuteMemoryTable' want's a string from array ???. What is the correct way to call 'ExecuteMemoryTable' with arguments?.See code snippet below. Any help to get further appreciated

B4X:
#AdditionalJar: sqlite-jdbc-3.7.2





Sub Process_Globals
.
.
.

Private sql1 As SQL
End Sub


Sub AppStart (Form1 As Form, Args() As String)
.
.
.
.
.

'open DB
Try
        sql1.InitializeSQLite(File.DirApp,"data/rflink_data.db", False)
        Log("Database open")
    Catch
        Log("Unable to open database")
        End Try
        
    Find_device("TEST")' JUST FOR TEST !!!!!!
End Sub



Sub Find_device(tmpDevice As String)

    Dim mlist As List
    mlist.Initialize
    mlist=DBUtils.ExecuteMemoryTable(sql1,"SELECT * FROM switches WHERE Name =?" ,tmpDevice,0)
    Log("mlist" & mlist)
End Sub

If I pass arguments with 'NULL' it compiles ok
mlist=DBUtils.ExecuteMemoryTable(sql1,"SELECT * FROM switches WHERE Name = TEST" ,Null,0)

ERROR OUTPUT ON COMPILE
B4J Version: 5.80
Parsing code. (0.03s)
Compiling code. Error
Error compiling program.
Error description: Cannot cast type: {Type=String,Rank=0, RemoteObject=True} to: {Type=String,Rank=1, RemoteObject=True}
Error occurred on line: 368
mlist=DBUtils.ExecuteMemoryTable(sql1,"SELECT * FROM switches WHERE Name =?" ,tmpDevice,0)
Word: tmpdevice

Regards Håkan
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4J Version: 5.80
Why aren't you using the latest version?

If I understand things right you can't use ordinary SQL commands like 'SQLExecute' ?
You can use whichever SQL command you like and is supported by the SQL engine.
DBUtils is just a code module with several useful utility methods.


The correct code is:
B4X:
    Dim mlist As List = DBUtils.ExecuteMemoryTable(sql1,"SELECT * FROM switches WHERE Name =?" ,Array As String(tmpDevice),0)
 
Upvote 0

hakha4

Member
Licensed User
Longtime User
Awesome! Never figured that out by myself. So every time I need to insert a argument in an SQL the syntax is '
Array As String(x)' when using dbutils?

I thought I was running latest ver!,I'll find latest and download
I'll tried SQLExecute(SQL...) => no such method error so I assumed it was not included in SQLlite. I keep on Google to learn.
Thanks for excellent support
Regards Håkan

 
Upvote 0
Top