Android Question How run a set of queries one time (Sqlite)

Ajws

Member
Licensed User
HI all,

How run a set of queries one time (Sqlite)


Examples :
Str ="insert into tbla (a,b,c) values('a','b','c');insert into tbla (a,b,c) values('d','e','f');insert into tbla (a,b,c) values('f','g','h');"

sql1.ExecNonQuery(Str) --> just run insert into tbla (a,b,c) values('a','b','c')


Regards
Ajws
 

Ajws

Member
Licensed User
so slow

but i found the answer
change Str from
Str ="insert into tbla (a,b,c) values('a','b','c');insert into tbla (a,b,c) values('d','e','f');insert into tbla (a,b,c) values('f','g','h');"

to
Str ="insert into tbla (a,b,c) values('a','b','c'),('d','e','f'),('f','g','h')"

sql1.ExecNonQuery(Str)

ok thanks erel...
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Str ="insert into tbla (a,b,c) values('a','b','c'),('d','e','f'),('f','g','h')"
sql1.ExecNonQuery(Str)
It is a lot easier to use a parameterized query like this, less prone to error:
B4X:
Dim str As String
    str="INSERT INTO tbla  VALUES(?,?,?), (?,?,?), (?,?,?)"
    SQL1.ExecNonQuery2(str, Array As Object("a","b","c","d","e","f","g","h","i") )
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Just out of interest what are you trying to achieve here? The approach doesn't sound right to me, but we haven't got the full picture.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
The approach doesn't sound right to me,
His idea is sound. I have used that approach. It works well and the same way as using many separate INSERT statements as long as he uses a transaction. All he is trying to do is have one insert statement for several records insertions. There is no gain or loss of speed. But, I will let him explain his point of view.
 
Upvote 0

eps

Expert
Licensed User
Longtime User

Hi @Mahares I'm not quibbling on the technical aspect, but the need to perform this processing - it doesn't sound right to me - but then we don't know the intended use or problem being solved here.
 
Upvote 0

Ajws

Member
Licensed User
@Mahares : thank you for your answer..
@eps : i try download data from server (more than 10.000 rows (Mysql)) and insert into my local database (SQLite)
@Erel : thank you, transaction will be my favorite (faster than i think)
I try with transaction and
he result is faster than i need
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…