Illuma Posted November 17, 2010 Share Posted November 17, 2010 Ok, Don't shout I know I am going blind the answer is out there I just cant find it! I am totally new to SQL database stuff and I am attempting to put data in the database from a variable, however I cant seem to work it out. This is the line I am using:- _SQLite_Exec (-1, "INSERT INTO BarcodeInfo (ScanTime,ScanDate,Barcode,MachineNumber,Points) VALUES ( $Time,'2','05500103641113','055','123');") From this if I was to replace $Time with '1' all the data gets put in the database, what I am now trying to do is put actual data in not test data so if $Time = 15:30 how do I put that in?? It's driving me nuts! Thanks in advance. Mark Link to comment Share on other sites More sharing options...
PsaltyDS Posted November 17, 2010 Share Posted November 17, 2010 You have to make your variable reference outside the quoting: _SQLite_Exec (-1, "INSERT INTO BarcodeInfo (ScanTime,ScanDate,Barcode,MachineNumber,Points) VALUES (" & $Time & ",'2','05500103641113','055','123');") If the value requires literal single quotes around it, then: _SQLite_Exec (-1, "INSERT INTO BarcodeInfo (ScanTime,ScanDate,Barcode,MachineNumber,Points) VALUES ('" & $Time & "','2','05500103641113','055','123');") Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law Link to comment Share on other sites More sharing options...
Illuma Posted November 17, 2010 Author Share Posted November 17, 2010 Thanks PsaltyDS, I can't believe I missed the second &, I tried " $Time ", arghhh. Regards Mark Link to comment Share on other sites More sharing options...
jchd Posted November 17, 2010 Share Posted November 17, 2010 As a reminder, when a text column (or a text value, since SQLite doesn't actually strictly enforce column types) _may_ even remotely contain one or more single quote, then you must use _SQLite_Escape($text) instead of $text alone. This way, you're safe as any single quote within text will be transparently escaped. I personally always use an equivalent function to wrap any text value in any table. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Illuma Posted November 17, 2010 Author Share Posted November 17, 2010 As a reminder, when a text column (or a text value, since SQLite doesn't actually strictly enforce column types) _may_ even remotely contain one or more single quote, then you must use _SQLite_Escape($text) instead of $text alone. This way, you're safe as any single quote within text will be transparently escaped. I personally always use an equivalent function to wrap any text value in any table.Way over my head! Thanks for the info though. Link to comment Share on other sites More sharing options...
jchd Posted November 17, 2010 Share Posted November 17, 2010 That's simple: SQL expect a litteral text value to be surrounded by quotes. E.g. "insert into mytable (a,b,c) values (1, 'Illuma', '2010-11-17')". If your text contains one or more quote, you need to escape each of them by doubling then. E.g. "insert into mytable (a,b,c) values (1, 'Illuma: it''s very simple', '2010-11-17')" here it's needs to be passed a it''s (two single quotes). That's exactly what _SQLite_Escape does for you. Omitting this you end up passing ... values (1, 'Illuma: it's very simple', '2010-11-17') and the part in bold causes an error in an otherwise working program because the quote encountered is parsed as the closing quote of the litteral text, while it really is part of the text. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now