check the Table if exist

Sinan Tuzcu

Well-Known Member
Licensed User
Longtime User
Helo,

can i checked the table, if the exist with follow code

Code: Copy
SQL1.ExecNonQuery("DROP TABLE IF EXISTS" & Name & ")

gruß
sinan
 
helo,

I would only check if the table exists, if not, then I want to create it.
Code: Copy
SQL1.ExecNonQuery("DROP TABLE IF EXISTS" & ayir2(0) & ")
SQL1.ExecNonQuery("CREATE TABLE"  & ayir2(0) & "(Nummer TEXT , Name TEXT, Mesaj TEXT , LinkAdres TEXT, Datum TEXT)")
SQL1.ExecNonQuery2("INSERT INTO"  & ayir2(0) & "VALUES(?,?,?,?,?)", Array As Object(ayir2(0), ayir2(1), ayir2(2), ayir2(3),ayir2(4)))

but doesn't work
 
Upvote 0
Replace this line:
Code: Copy
SQL1.ExecNonQuery("DROP TABLE IF EXISTS" & ayir2(0) & ")
with this line:
Code: Copy
SQL1.ExecNonQuery("DROP TABLE IF EXISTS " & ayir2(0))
Notice the space after EXISTS

EDIT: I forgot to mention also that you need a space here after TABLE like this: ("CREATE TABLE "
Also, you need a space after INTO like this: "INSERT INTO "
 
Last edited:
Upvote 0
Replace this line:
Code: Copy
SQL1.ExecNonQuery("DROP TABLE IF EXISTS" & ayir2(0) & ")
with this line:
Code: Copy
SQL1.ExecNonQuery("DROP TABLE IF EXISTS " & ayir2(0))
Notice the space after EXISTS

EDIT: I forgot to mention also that you need a space here after TABLE like this: ("CREATE TABLE "
Also, you need a space after INTO like this: "INSERT INTO "

only after TABLE ?
and here & ayir2(0) & " VALUES
between & and values?
 
Upvote 0
@Sinan: Here is the code with all the necessary spaces and syntax:
Code: Copy
SQL1.ExecNonQuery("DROP TABLE IF EXISTS " & ayir2(0))
SQL1.ExecNonQuery("CREATE TABLE "  & ayir2(0) & " (Nummer TEXT , Name TEXT, Mesaj TEXT , LinkAdres TEXT, Datum TEXT)")
SQL1.ExecNonQuery2("INSERT INTO "  & ayir2(0) & " VALUES(?,?,?,?,?)", Array As Object(ayir2(0), ayir2(1), ayir2(2), ayir2(3),ayir2(4)))
 
Upvote 0
you can use
Code: Copy
if(table_name.compareto(SQ.ExecQuerySingleResult("Select name From sqlite_master WHERE Type='table' AND name='"& table_name & "'"))==0)then
log("Table exist")
else
log("Table don't exist")
end if
 
Upvote 0
you can use
Code: Copy
if(table_name.compareto(SQ.ExecQuerySingleResult("Select name From sqlite_master WHERE Type='table' AND name='"& table_name & "'"))==0)then
log("Table exist")
else
log("Table don't exist")
end if


Helo,

this code doesn't working
 
Upvote 0
table_name is name of table .....
Code: Copy
SQ.ExecQuerySingleResult("Select name From sqlite_master WHERE Type='table' AND name='"& table_name & "'")
this code returns table name if table exist otherwise it returns null.
 
Upvote 0

Similar Threads

Back
Top