kylomas Posted March 12, 2011 Share Posted March 12, 2011 SQLite Experts, What is a common table insert practice, test for the record and insert if it does not exist or insert and test for duplicate return code? This seems like a "it depends..." kind of situation. Searches on Google show it done both ways. kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
MvGulik Posted March 12, 2011 Share Posted March 12, 2011 Don't forget the SQlite help itself.http://www.sqlite.org/lang.htmlSeems that REPLACE might be the one your looking for.(also take a look at ON CONFLICT) "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
jchd Posted March 12, 2011 Share Posted March 12, 2011 It all depends on your schema and its underlying rules. Logical use of either a (hidden) rowid or an integer primary key can make a huge difference, whether you handle the id yourself or leave SQLite create one for you. Never forget that INSERT OR REPLACE will first delete one or more existing row(s) then insert one anew. If you have FK on the deleted row(s) it may not be what you need! AFAICT there is no definitive "rule", every situation calls for its own logic. 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...
kylomas Posted March 12, 2011 Author Share Posted March 12, 2011 Thank you, gentelmen. @iEvKI3gv9Wrkd41u - I have read that doc and others and use it for reference. I have a local copy of it. I wish that it had examplem, however. Do you mind if I ask you how you came up with that screen name and what it means? @jhcd - Yes, I thought a much. Unfortunately I do not yet understand enough about DB management to make any intelligent decisions regarding DB organization. I am planning the schema (is that the word that describes the DB organization?) now. It seems like a trivial event, but I am tickled pink that I actually have a DB loaded. I read much of what you posted and learned enough to get something going. I have a mountain of questions but this forum is hardly the place for DBA type discussions. I'll keep digging till I get it. I used the transaction batching technique that you recently advised on another post. The difference on my computer is at least 300% (probably due to minimized I/O activity). kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
MvGulik Posted March 13, 2011 Share Posted March 13, 2011 (edited) Do you mind if I ask you how you came up with that screen name and what it means?I did not and it means nothing. Its just a random generated (password) string. (Its my actual login name on this forum)... kinda boring, but thats the way it is ... Edited March 14, 2011 by iEvKI3gv9Wrkd41u "Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions.""The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014) "Believing what you know ain't so" ... Knock Knock ... Link to comment Share on other sites More sharing options...
jchd Posted March 13, 2011 Share Posted March 13, 2011 You'll certainly benefit from freely digging into the SQLite mailing list archive which is the premium mine of information both theoritical and practical. 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...
Xenobiologist Posted March 14, 2011 Share Posted March 14, 2011 (edited) Hi, normally, you do know whether the key already exists. (Programmatical logic) Guess what: If you don't know then there are several ways to get it done. 1 ) Check for key (via SQL) e.g. by return code a ) if it exsis, then update b ) if not, then insert 2 ) Firstly make a delete then an insert 3 ) Using a special command (depends on the used database) E.g. in DB2 >= V9 you can try using Merge. You can also create your own function which provides the logic/code. Mega Edited March 14, 2011 by Xenobiologist Scripts & functions Organize Includes Let Scite organize the include files Yahtzee The game "Yahtzee" (Kniffel, DiceLion) LoginWrapper Secure scripts by adding a query (authentication) _RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...) Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc. MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times Link to comment Share on other sites More sharing options...
jchd Posted March 14, 2011 Share Posted March 14, 2011 Yes, that or much more simply, declare a ON CONFLICT IGNORE on the unique column(s) and forget about applicative code complexity. 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...
Zedna Posted March 14, 2011 Share Posted March 14, 2011 Just execute Select Count(*) from table where id = value before your INSERT statement This way you can see if it already exists in the table. Resources UDF ResourcesEx UDF AutoIt Forum Search 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