Re: [sqlite] Feature request, Prevent Master Journal file.
Ken - You could write your own VFS that overrides the xOpen method so that it doesn't create a journal file. Quoting from the documentation: "The file I/O implementation can use the object type flags to change the way it deals with files. For example, an application that does not care about crash recovery or rollback, might make the open of a journal file a no-op. Writes to this journal are also a no-op. Any attempt to read the journal returns SQLITE_IOERR." The object type flags referred to in the above paragraph are included in the 'flags' parameter passed to xOpen. See http://www.sqlite.org/34to35.html for more details. - Richard Ken wrote: > Maybe this could be added as a "Feature request" to open_v2 ? > > Add, > > #define SQLITE_OPEN_OMIT_JOURNAL 0x8000 > > Test this flag and set the omit_journal parameter to Btree factory... To > cause sqlite to omit journal creation. Obviously this has serious impact to a > databases recoverability. But when the Durability component of ACID is not > needed it should provide a nice performance boost! > > In my particular case, I have many small db files that have data. These are > "batched" into a db file. If the process fails the in progress batch will > simply be overwritten and re-created. Hence it is an all or none approach and > does not need any recoverability. > > Thanks, > Ken > > > > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to get the number of minutes
On 3/18/08, P Kishor <[EMAIL PROTECTED]> wrote: > On 3/18/08, Joanne Pham <[EMAIL PROTECTED]> wrote: > > Hi All > > I ran the following statement: > > select datetime(startTime *60, 'unixepoch','-8 hours') , bytesIn from > wanPerfTable where appId = 30 and remoteWXId = 200; > > and below is my output. > > > > 2007-12-03 11:00:00 20 > > 2007-12-03 11:01:00 5 > > 2007-12-03 11:02:00 100 > > 2007-12-03 11:03:00 50 > > 2007-12-03 11:58:00 50 > > > > > > I would like to return only the number of minutes as below > > 0 20 > > 1 5 > > 2 100 > > 3 50 > > 58 25 > > > > So would you please help > > select strftime('%M', datetime(startTime *60, 'unixepoch','-8 hours')); I should add that I have no idea what format startTime is in, but you could possibly simplify all that by applying strftime directly to startTime if it is already amenable to such manipulation. > > you do know that all the datetime options are documented at > http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions > > > Thanks, > > > > > > > > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to get the number of minutes
On 3/18/08, Joanne Pham <[EMAIL PROTECTED]> wrote: > Hi All > I ran the following statement: > select datetime(startTime *60, 'unixepoch','-8 hours') , bytesIn from > wanPerfTable where appId = 30 and remoteWXId = 200; > and below is my output. > > 2007-12-03 11:00:00 20 > 2007-12-03 11:01:00 5 > 2007-12-03 11:02:00 100 > 2007-12-03 11:03:00 50 > 2007-12-03 11:58:00 50 > > > I would like to return only the number of minutes as below > 0 20 > 1 5 > 2 100 > 3 50 > 58 25 > > So would you please help select strftime('%M', datetime(startTime *60, 'unixepoch','-8 hours')); you do know that all the datetime options are documented at http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions > Thanks, > > > > > > Never miss a thing. Make Yahoo your home page. > http://www.yahoo.com/r/hs > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- Puneet Kishor http://punkish.eidesis.org/ Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/ Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to get the minutes number only
Joanne Pham wrote: > > > > > I would like to return only the number of minutes as below > The strftime function is your friend: http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions HTH, Gerry ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to get the minutes number only
Joanne Pham <[EMAIL PROTECTED]> wrote: > Hi All > I ran the following statement: > select datetime(startTime *60, 'unixepoch','-8 hours') , bytesIn from > wanPerfTable where appId = 30 and remoteWXId = 200; > and below is my output. > > 2007-12-03 11:00:00 20 > 2007-12-03 11:01:00 5 > 2007-12-03 11:02:00 100 > 2007-12-03 11:03:00 50 > 2007-12-03 11:58:00 50 > > > I would like to return only the number of minutes as below > 0 20 > 1 5 > 2 100 > 3 50 > 58 25 > strftime('%M', startTime*60, 'unixepoch', '-8 hours'); -- D. Richard Hipp <[EMAIL PROTECTED]> ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] SQL logic error or missing database in version 3.5.6 (Bug???)
"Steve Topov" <[EMAIL PROTECTED]> wrote: > Hello, > > Recently I upgraded SQLite to version 3.5.6 and discovered that my > program cant work anymore with some database files. Sqlite3_open > returns OK, but when I am trying to execute any SQL statement it returns > SQL logic error or missing database. > For example sqlite3_prepare returns 1 instead of 0. Same for > sqlite3_execute. > I do not think it is my code that causes the problem because I can just > switch SQLite dll from version 3.5.6 to version 3.3.5 and everything > works fine. > I do not know the version of SQLite the database file in question was > created with. Few database files created with version 3.3.5 does not > have this problem. > I tried to upgrade to the version 3.5.7 same result. > SQLite versions 3.5.6 and 3.5.7 are suppose to be able to read and write any database written by any prior version of SQLite going back to version 3.0.0. Perhaps you have a version 2 database file? If you database file is named XYZ.db, what does this command show you: od -c XYZ.db | head -- D. Richard Hipp <[EMAIL PROTECTED]> ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] SQLITE_CONSTRAINT error after sqlite3_step
On Tue, Mar 18, 2008 at 04:06:04PM -0600, Dennis Cote scratched on the wall: > Vincent Vega wrote: > > query = sqlite3_mprintf("Insert into Inventory (Tag) values (?)"); > > This allocates memory and saves a pointer to it in query. My question is why use "sqlite3_mprintf()" at all? You're not actually using any of the formatting functionality of _mprintf, only passing a string literal which is then copied into a newly allocated string. Since you're not modifying the string, there is no reason to make a copy of it. The string literal you're passing to _mprintf is going to be embedded into the application's memory space by the compiler. There is no reason to not just pass the literal (or a reference to it) directly to _prepare, which expects a const char* anyways. Most compilers are even smart enough to combine multiple equivalent string literals into a single reference, but just in case your compiler is not, you can just setup a global var like this... const char sql_insertInventory[] = "Insert into Inventory (Tag) " ...and then reference the global var any time you need to reference the actual query string. I tend to do this just to keep all the SQL string literals in one place, which helps with updates and changes. It also allows me to use symbolic names in the code, which is usually a good thing. In this case (since you're not changing the query string), it seems to me that the best way to avoid leaking memory is not to allocate it in the first place. > > rc=sqlite3_prepare_v2(DB,query ,-1,,NULL); If you do have some reason for using _mprintf to allocate "query", you can/should de-allocate it right after this. Once the statement is prepared, the literal SQL string is no longer needed. The _prepare_v2 calls will keep a copy around, but everything I've seen leads me to believe that this is a private copy that is released with _finalize, and not something the user has to worry about. (right?) -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "'People who live in bamboo houses should not throw pandas.' Jesus said that." - "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006" ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Last insert in a table
On 3/18/08, A.J.Millan <[EMAIL PROTECTED]> wrote: > From: "P Kishor" <[EMAIL PROTECTED]> > > > >> I would know if there a some way to know the last insert in a know > >> table. > >> > >> Some like the result returned by sqlite3_last_insert_rowid(), but > >> referred > >> to a specific table inside the database connection, and not in all > >> tables > >> into the database from the database connection. > > > > > last_insert_rowid() is indeed the result of the insert into a > > *specific* table, the one that happens to have a row inserted at the > > very last! You can't possibly insert the "last" row in *all* the > > tables just like you can't take away the last coach from a train... no > > matter what you take away, there will always be a last one. > > > > When the *next* insert operation happens, the result of that insert > > will become the last insert. > > > > Puneet: > > Thanks for your reply, but let me be a bit more concise. > > I need update several tables in a dBase, and after all, I need to know the > las insert id of one, or several of them. > > Odviously I can keep a variable with the last_insert_rowid() of each > specific table, obtained inmediately after the update of the table/s of my > interest, but I try avoid global variables, so my question. > > Thanks anyway. > > > A.J.Millan > > Dennis Cote offered the most elegant and concise solution, that of creating a new table to keep track of the last row inserted in each table. Something that I also envision I can use in certain circumstances. Puneet. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Preventing Master Journal Files
Looks like Sqlite is not the right storage tool for your application since you don't want transactional integrity. How about something like Berkeley DB. Ken wrote: > Hello list, > > How do I prevent the creation of a journal file and a master journal file? I > need to be able to do this dynamically not just a compile time flag. > > The process does not need recovery as it is an all or none for some of the > DB's it creates. And is restarted from the beginning in the event of a crash. > > Thanks, > Ken > > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] How to get the number of minutes
Hi All I ran the following statement: select datetime(startTime *60, 'unixepoch','-8 hours') , bytesIn from wanPerfTable where appId = 30 and remoteWXId = 200; and below is my output. 2007-12-03 11:00:00 20 2007-12-03 11:01:00 5 2007-12-03 11:02:00 100 2007-12-03 11:03:00 50 2007-12-03 11:58:00 50 I would like to return only the number of minutes as below 0 20 1 5 2 100 3 50 58 25 So would you please help Thanks, Never miss a thing. Make Yahoo your home page. http://www.yahoo.com/r/hs ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to get the minutes number only
- Original Message From: Joanne Pham <[EMAIL PROTECTED]> To: General Discussion of SQLite DatabaseSent: Tuesday, March 18, 2008 4:40:54 PM Subject: How to get the minutes number only Hi All I ran the following statement: select datetime(startTime *60, 'unixepoch','-8 hours') , bytesIn from wanPerfTable where appId = 30 and remoteWXId = 200; and below is my output. 2007-12-03 11:00:00 20 2007-12-03 11:01:00 5 2007-12-03 11:02:00 100 2007-12-03 11:03:00 50 2007-12-03 11:58:00 50 I would like to return only the number of minutes as below 0 20 1 5 2 100 3 50 58 25 So would you please help Thanks, JP Never miss a thing. Make Yahoo your homepage. Never miss a thing. Make Yahoo your homepage. Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Feature request, Prevent Master Journal file.
Maybe this could be added as a "Feature request" to open_v2 ? Add, #define SQLITE_OPEN_OMIT_JOURNAL 0x8000 Test this flag and set the omit_journal parameter to Btree factory... To cause sqlite to omit journal creation. Obviously this has serious impact to a databases recoverability. But when the Durability component of ACID is not needed it should provide a nice performance boost! In my particular case, I have many small db files that have data. These are "batched" into a db file. If the process fails the in progress batch will simply be overwritten and re-created. Hence it is an all or none approach and does not need any recoverability. Thanks, Ken ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] How to get the minutes number only
Hi All I ran the following statement: select datetime(startTime *60, 'unixepoch','-8 hours') , bytesIn from wanPerfTable where appId = 30 and remoteWXId = 200; and below is my output. 2007-12-03 11:00:00 20 2007-12-03 11:01:00 5 2007-12-03 11:02:00 100 2007-12-03 11:03:00 50 2007-12-03 11:58:00 50 I would like to return only the number of minutes as below 0 20 1 5 2 100 3 50 58 25 So would you please help Thanks, JP Never miss a thing. Make Yahoo your homepage. Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Last insert in a table
On Tue, Mar 18, 2008 at 08:07:12PM +0100, A.J.Millan scratched on the wall: > Hi all: > > I would know if there a some way to know the last insert in a know table. > > Some like the result returned by sqlite3_last_insert_rowid(), but referred > to a specific table inside the database connection, and not in all tables > into the database from the database connection. You could simply look for the largest ROWID in a table. Assuming your tables have no INTEGER PRIMARY KEY column (or if they do, that you never set it explicitly) then, in general, the row with the largest ROWID will be the last one that was inserted. There are a few caveats to that, however. Having an INTEGER PRIMARY KEY AUTOINCREMENT column may help limit these issues. See http://www.sqlite.org/autoinc.html for more details. Of course this depends on a lot of things that are somewhat out of your control. You're depending on the specific way the SQLite uses "behind the scenes" data and the behavior of the allocation of those ID values. If it is really that important to know the last inserted row, it might be best to just have some kind of integer timestamp column that is auto-set when a row is inserted. This makes it easy to look up the last-inserted row regardless of the rest of the table design. -j -- Jay A. Kreibich < J A Y @ K R E I B I.C H > "'People who live in bamboo houses should not throw pandas.' Jesus said that." - "The Ninja", www.AskANinja.com, "Special Delivery 10: Pop!Tech 2006" ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] How to get the minutes number only
Hi All I ran the following statement: select datetime(startTime *60, 'unixepoch','-8 hours') , bytesIn from wanPerfTable where appId = 30 and remoteWXId = 200; and below is my output. 2007-12-03 11:00:00 20 2007-12-03 11:01:00 5 2007-12-03 11:02:00 100 2007-12-03 11:03:00 50 2007-12-03 11:58:00 50 I would like to return only the number of minutes as below 0 20 1 5 2 100 3 50 58 25 So would you please help Thanks, JP Be a better friend, newshound, and know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Last insert in a table
From: "P Kishor" <[EMAIL PROTECTED]> >> I would know if there a some way to know the last insert in a know >> table. >> >> Some like the result returned by sqlite3_last_insert_rowid(), but >> referred >> to a specific table inside the database connection, and not in all >> tables >> into the database from the database connection. > > last_insert_rowid() is indeed the result of the insert into a > *specific* table, the one that happens to have a row inserted at the > very last! You can't possibly insert the "last" row in *all* the > tables just like you can't take away the last coach from a train... no > matter what you take away, there will always be a last one. > > When the *next* insert operation happens, the result of that insert > will become the last insert. Puneet: Thanks for your reply, but let me be a bit more concise. I need update several tables in a dBase, and after all, I need to know the las insert id of one, or several of them. Odviously I can keep a variable with the last_insert_rowid() of each specific table, obtained inmediately after the update of the table/s of my interest, but I try avoid global variables, so my question. Thanks anyway. A.J.Millan ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Last insert in a table
A.J.Millan wrote: > > I would know if there a some way to know the last insert in a know table. > > Some like the result returned by sqlite3_last_insert_rowid(), but referred > to a specific table inside the database connection, and not in all tables > into the database from the database connection. > No, that functionality doesn't exist. You can create it yourself by adding a table to keep track of this information, and adding a after insert trigger to each table to update the information. -- data tables create table t1(id, a, b); create table t2(id, b, c, d); -- create table to store insert rowids create table last_inserted_rows ( table_name text primary key, last_inserted_row integer ); -- initialize table with names of data tables insert into last_inserted_rows values ('t1', null); insert into last_inserted_rows values ('t2', null); -- add triggers to data tables create trigger in_t1_upd after insert on t1 begin update last_inserted_rows set last_inserted_row = last_insert_rowid() where table_name = 't1'; end; create trigger in_t2_upd after insert on t2 begin update last_inserted_rows set last_inserted_row = last_insert_rowid() where table_name = 't2'; end; Now when you need the last inserted row for a particular table you can get it by querying the last_inserted_rows table. select last_inserted_row from last_inserted_rows where table_name = :table_name; HTH Dennis Cote ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to decode a date
[EMAIL PROTECTED] wrote: > > I would like to know how to decode a Date when I read a table. The same > question for Time. > See http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions for details. HTH Dennis Cote ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Preventing Master Journal Files
Ken wrote: > Hello list, > > How do I prevent the creation of a journal file and a master journal > file? I need to be able to do this dynamically not just a compile > time flag. > I don't think you can do this. A journal file is always created except for in memory databases. You can change the synchronous pragma to off to get most of the speed benefits of operation without a journal, but the file will still be created. Execute "pragam synchronous = off" to disable file syncs, and when done, execute "pragma synchronous = full" to return to normal operation. HTH Dennis Cote ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] SQLITE_CONSTRAINT error after sqlite3_step
Vincent Vega wrote: > Well , since I do need to avoid a case where duplicated tags are > inserted ,I have added a treatment to the case of SQLITE_CONSTRAINT. OK, but what you have shown doesn't do anything useful. If your Tag values must really be unique, then it is an error to insert a duplicate Tag value. There is really nothing to do except possibly report the error. If you believe the Tag value that are being inserted are supposed to be unique then you might want to rollback your transaction on a constraint error (which is what you get when you break the uniqueness constraint on the Tag column). > I am just curious whether I need to call sqlite3_finalize(Statement) > after sqlite3_step(Statement) returns SQLITE_CONSTRAINT so that the > memory that was allocated at sqlite3_mprintf be released ? > Yes and no. You do need to finalize the statement to release resources allocated when the statement was prepared. In addition, you also need to call sqlite3_free() to release the memory allocated by sqlite3_mprintf(). These are separate allocations and require separate release calls. > Here are the table defenitions : > CREATE TABLE 'Inventory' ( > 'TagIndex' integer PRIMARY KEY, > 'Tag' varchar(12) NOT NULL, > ) ; > CREATE UNIQUE INDEX InventoryIndex ON Inventory (Tag); > The word unique between create and index is what causes the constraint error you are seeing. This only happens if you insert a duplicate Tag value. > My code looks like this: > > query = sqlite3_mprintf("Insert into Inventory (Tag) values (?)"); This allocates memory and saves a pointer to it in query. > rc=sqlite3_prepare_v2(DB,query ,-1,,NULL); This allocates a statement and saves a pointer to it in Statement. > if (rc!=SQLITE_OK) > error_print(); > > sqlite3_exec(db,"BEGIN;",NULL,NULL,); > for (i=1;i<500;i ++) > { > rc=sqlite3_bind_text(Statement,1,list[i],-1,NULL); This binds the i'th value in the array list to the parameter that will be inserted into the Tag column. > if (rc!=SQLITE_OK) > error_print(); > rc=sqlite3_step(Statement); This executes the statement. Either inserting the value and assigning a new TagIndex and then returning SQLITE_DONE, or doing nothing and returning SQLITE_CONSTRAINT. > if (rc!=SQLITE_DONE) > { > if (rc==SQLITE_CONSTRAINT ) > { You end up here if your list has duplicate entries. > query = sqlite3_mprintf("Insert into Inventory (Tag) values > (?)"); This overwrites the pointer stored in query. The previous value is lost and memory is leaked. You must use a different pointer or call sqlite3_free() to release the old value first. > rc=sqlite3_prepare_v2(DB,query ,-1,,NULL); This overwrites the statement pointer stored in Statement. The previous value is lost and memory is leaked. You must use a different pointer or call sqlite3_finalize() to release the old value first. > if (rc!=SQLITE_OK) > error_print(); > } > error_print(); > } > sqlite3_reset(Statement) ; > } > sqlite3_finalize(Statement) ; This releases the statement allocated by prepare above. > > sqlite3_exec(db,"END;",NULL,NULL,) ; The string query is never released. Call sqlite3_free() to do so. I'm not sure what you are trying to accomplish when you detect the SQLITE_CONSTRAINT error returned from sqlite3_step(). Re-preparing the same SQL statement again will not correct anything. Your list has real duplicate values, you have told SQLite not to accept duplicate values, and it has told you that you have tried to enter a duplicate value. You really need to ignore the duplicate and continue (possibly reporting the duplicate), or abort, fix your list to remove the duplicates, and then try again later. This code should probably be changed to something like this depending upon exactly what you want to do if your list contains duplicates: query = sqlite3_mprintf("Insert into Inventory (Tag) values (?)"); rc=sqlite3_prepare_v2(DB,query ,-1,,NULL); if (rc!=SQLITE_OK) error_print(); int abort = 0; sqlite3_exec(db,"BEGIN;",NULL,NULL,); for (i=1;i<500;i ++) { rc=sqlite3_bind_text(Statement,1,list[i],-1,NULL); if (rc!=SQLITE_OK) error_print(); rc=sqlite3_step(Statement); if (rc!=SQLITE_DONE) { // SQLITE_CONSTRAINT error abort = 1; // uncomment this line to report errors error_print(); // comment this line to ignore errors break; } sqlite3_reset(Statement) ; } sqlite3_finalize(Statement) ; sqlite3_free(query); if (abort) sqlite3_exec(db, "ROLLBACK", NULL, NULL, ); else sqlite3_exec(db,"COMMIT",NULL,NULL,) ; HTH Dennis Cote ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Last insert in a table
On 3/18/08, A.J.Millan <[EMAIL PROTECTED]> wrote: > Hi all: > > I would know if there a some way to know the last insert in a know table. > > Some like the result returned by sqlite3_last_insert_rowid(), but referred > to a specific table inside the database connection, and not in all tables > into the database from the database connection. last_insert_rowid() is indeed the result of the insert into a *specific* table, the one that happens to have a row inserted at the very last! You can't possibly insert the "last" row in *all* the tables just like you can't take away the last coach from a train... no matter what you take away, there will always be a last one. When the *next* insert operation happens, the result of that insert will become the last insert. > > Thanks in advance > > A.J.Millan > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > -- Puneet Kishor http://punkish.eidesis.org/ Nelson Institute for Environmental Studies http://www.nelson.wisc.edu/ Open Source Geospatial Foundation (OSGeo) http://www.osgeo.org/ ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to decode a date
[EMAIL PROTECTED] wrote: > Hello, > > I would like to know how to decode a Date when I read a table. The same > question for Time. The wiki on this question is quite good (and not just because I editted some of it). http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions -- Scott Baker - Canby Telcom RHCE - System Administrator - 503.266.8253 ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] How to decode a date, I found the answer !
> -Message d'origine- > De : Rodrigue, Michel (TIT-SA) > Envoyé : 2008-03-18 14:49 > À : 'sqlite-users@sqlite.org' > Objet : How to decode a date > > Hello, > > I would like to know how to decode a Date when I read a table. The same > question for Time. > > Thank you very much. > __ > Michel Rodrigue, B.Sc.A. > Conseiller en systèmes d'information > Ville de Québec > > > > > > > > > I have found the answer at > http://www.sqlite.org/cvstrac/wiki?p=DateAndTimeFunctions > > Thank you very much > > Michel Rodrigue > > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Last insert in a table
Hi all: I would know if there a some way to know the last insert in a know table. Some like the result returned by sqlite3_last_insert_rowid(), but referred to a specific table inside the database connection, and not in all tables into the database from the database connection. Thanks in advance A.J.Millan ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] How to decode a date
Hello, I would like to know how to decode a Date when I read a table. The same question for Time. Thank you very much. __ Michel Rodrigue, B.Sc.A. Conseiller en systèmes d'information Ville de Québec ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Malformed database schema with SQLite version > 3.5.x
MarcoN <[EMAIL PROTECTED]> wrote: > Yes, of course I can send you the DB: the file is under 1MB, about 100K if > compressed via .zip > Can I send it to you via e-mail? > Thanks very much for the support > Please send the database directly to my email address shown below. -- D. Richard Hipp <[EMAIL PROTECTED]> ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Preventing Master Journal Files
Hello list, How do I prevent the creation of a journal file and a master journal file? I need to be able to do this dynamically not just a compile time flag. The process does not need recovery as it is an all or none for some of the DB's it creates. And is restarted from the beginning in the event of a crash. Thanks, Ken ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] algorithm for adding columns to a table
Yes. I did this in my custom version of SQLite. If statement is ALTER TABLE, and SQLite returns error, I check if it´s ALTER TABLE (t) MODIFY COLUMN ou DROP COLUMN, doing the exact flow you did. -Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Derrell Lipman Sent: terça-feira, 18 de março de 2008 11:26 To: General Discussion of SQLite Database Subject: [sqlite] algorithm for adding columns to a table I could use another set of eyes or three to verify that this algorithm makes sense. I have legacy sqlite2 databases for which I need a generic function to add columns to tables. This is the pseudocode for the function. Am I missing anything? In this pseudocode, the parameters are: :tableName: The table name being altered :newColumnDefinition: The complete text of the new column description, as if it were in a CREATE TABLE command, e.g. "t TIMESTAMP DEFAULT '2008-03-18 10:08:47'" :newColumnValue: The value to insert into the new column as we add the new column to the table. Of course, all queries need error checking which is not included in the pseudocode. Errors cause an immediate rollback. Pseudocode follows... // If anything fails, ensure we can get back to our original query("begin;") // Get the sql to generate the table tableDef = query( "SELECT sql FROM sqlite_master WHERE tbl_name == :tableName: AND type = 'table';" ) // Get the indexes associated with this table, excluding automatic indexes indexes = query( "SELECT sql FROM sqlite_master WHERE tbl_name == :tableName: AND type = 'index' AND length(sql) > 0;" ) // Get the triggers associated with this table triggers = query( "SELECT sql FROM sqlite_master WHERE tbl_name == :tableName: AND type = 'trigger' AND length(sql) > 0;" ) // Copy all of the data to a temporary table query("CREATE TEMPORARY TABLE __t AS SELECT * FROM :tableName:;") // Drop the table being altered query("DROP TABLE :tableName:;") // Copy the original table definition so we can modify it sql = tableDef.sql; // Find the trailing right parenthesis in the original table definition p = strrchr(sql, ')'); // Where the right parenthesis was, append a comma and new column definition *p++ = ','; strcpy(p, :newColumnDefinition:); strcat(p, ");"); // Recreate the table using the new definition query(sql); // Copy the data from our temporary table back into this table. query("INSERT INTO :tableName: SELECT *, :newColumnValue: FROM __t;") // We don't need the temporary table anymore query("DROP TABLE __t;") // Recreate the indexes foreach index in indexes { query(index.sql) } // Recreate the triggers (after having copied the data back to the table!) foreach trigger in triggers { query(trigger.sql) } query("commit;") Thanks for any comments you can provide! Derrell ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] Preventing Master Journal Files.
How do I prevent the creation of a journal file and a master journal file? The process does not need recovery as it is an all or none. And is restarted from the beginning in the event of a crash. Thanks, Ken ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Malformed database schema with SQLite version > 3.5.x
Yes, of course I can send you the DB: the file is under 1MB, about 100K if compressed via .zip Can I send it to you via e-mail? Thanks very much for the support On Tue, Mar 18, 2008 at 1:10 PM, <[EMAIL PROTECTED]> wrote: > MarcoN <[EMAIL PROTECTED]> wrote: > > I actually don't know how to export it, because "SQLite Database > browser" > > (that is able to open the database and execute the query) has no way to > > export it; SQLiteSpy will not open the database because it is compiled > with > > a new SQLIte library version > > Maybe I can try to find an older version of SQLiteSpy on my archives, > but I > > need more time for this... > > > > Can you send me the entire database file? How big is it? > -- > D. Richard Hipp <[EMAIL PROTECTED]> > > ___ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Malformed database schema with SQLite version > 3.5.x
Yes, of course I can send you the DB: the file is under 1MB, about 100K if compressed via .zip Can I send it to you via e-mail? Thanks very much for the support ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] SQLITE_CONSTRAINT error after sqlite3_step
Well , since I do need to avoid a case where duplicated tags are inserted ,I have added a treatment to the case of SQLITE_CONSTRAINT. I am just curious whether I need to call sqlite3_finalize(Statement) after sqlite3_step(Statement) returns SQLITE_CONSTRAINT so that the memory that was allocated at sqlite3_mprintf be released ? Here are the table defenitions : CREATE TABLE 'Inventory' ( 'TagIndex' integer PRIMARY KEY, 'Tag' varchar(12) NOT NULL, ) ; CREATE UNIQUE INDEX InventoryIndex ON Inventory (Tag); My code looks like this: query = sqlite3_mprintf("Insert into Inventory (Tag) values (?)"); rc=sqlite3_prepare_v2(DB,query ,-1,,NULL); if (rc!=SQLITE_OK) error_print(); sqlite3_exec(db,"BEGIN;",NULL,NULL,); for (i=1;i<500;i ++) { rc=sqlite3_bind_text(Statement,1,list[i],-1,NULL); if (rc!=SQLITE_OK) error_print(); rc=sqlite3_step(Statement); if (rc!=SQLITE_DONE) { if (rc==SQLITE_CONSTRAINT ) { query = sqlite3_mprintf("Insert into Inventory (Tag) values (?)"); rc=sqlite3_prepare_v2(DB,query ,-1,,NULL); if (rc!=SQLITE_OK) error_print(); } error_print(); } sqlite3_reset(Statement) ; } sqlite3_finalize(Statement) ; sqlite3_exec(db,"END;",NULL,NULL,) ; - Original Message From: Dennis Cote <[EMAIL PROTECTED]> To: General Discussion of SQLite DatabaseSent: Monday, March 17, 2008 11:10:35 PM Subject: Re: [sqlite] SQLITE_CONSTRAINT error after sqlite3_step Vincent Vega wrote: > Thanks a lot . Your explantion does make sence. > I'll remove the UNIQUE index and see if it helps. > You probably shouldn't remove the index, just remove the unique keyword from the create index statement. create index InventoryIndex on Inventory (Tag); If you have an existing database you can drop the old index and create the new index without losing any data. HTH Dennis Cote ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users Looking for last minute shopping deals? Find them fast with Yahoo! Search. http://tools.search.yahoo.com/newsearch/category.php?category=shopping ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
[sqlite] algorithm for adding columns to a table
I could use another set of eyes or three to verify that this algorithm makes sense. I have legacy sqlite2 databases for which I need a generic function to add columns to tables. This is the pseudocode for the function. Am I missing anything? In this pseudocode, the parameters are: :tableName: The table name being altered :newColumnDefinition: The complete text of the new column description, as if it were in a CREATE TABLE command, e.g. "t TIMESTAMP DEFAULT '2008-03-18 10:08:47'" :newColumnValue: The value to insert into the new column as we add the new column to the table. Of course, all queries need error checking which is not included in the pseudocode. Errors cause an immediate rollback. Pseudocode follows... // If anything fails, ensure we can get back to our original query("begin;") // Get the sql to generate the table tableDef = query( "SELECT sql FROM sqlite_master WHERE tbl_name == :tableName: AND type = 'table';" ) // Get the indexes associated with this table, excluding automatic indexes indexes = query( "SELECT sql FROM sqlite_master WHERE tbl_name == :tableName: AND type = 'index' AND length(sql) > 0;" ) // Get the triggers associated with this table triggers = query( "SELECT sql FROM sqlite_master WHERE tbl_name == :tableName: AND type = 'trigger' AND length(sql) > 0;" ) // Copy all of the data to a temporary table query("CREATE TEMPORARY TABLE __t AS SELECT * FROM :tableName:;") // Drop the table being altered query("DROP TABLE :tableName:;") // Copy the original table definition so we can modify it sql = tableDef.sql; // Find the trailing right parenthesis in the original table definition p = strrchr(sql, ')'); // Where the right parenthesis was, append a comma and new column definition *p++ = ','; strcpy(p, :newColumnDefinition:); strcat(p, ");"); // Recreate the table using the new definition query(sql); // Copy the data from our temporary table back into this table. query("INSERT INTO :tableName: SELECT *, :newColumnValue: FROM __t;") // We don't need the temporary table anymore query("DROP TABLE __t;") // Recreate the indexes foreach index in indexes { query(index.sql) } // Recreate the triggers (after having copied the data back to the table!) foreach trigger in triggers { query(trigger.sql) } query("commit;") Thanks for any comments you can provide! Derrell ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Malformed database schema with SQLite version > 3.5.x
MarcoN <[EMAIL PROTECTED]> wrote: > I actually don't know how to export it, because "SQLite Database browser" > (that is able to open the database and execute the query) has no way to > export it; SQLiteSpy will not open the database because it is compiled with > a new SQLIte library version > Maybe I can try to find an older version of SQLiteSpy on my archives, but I > need more time for this... > Can you send me the entire database file? How big is it? -- D. Richard Hipp <[EMAIL PROTECTED]> ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Malformed database schema with SQLite version > 3.5.x
I actually don't know how to export it, because "SQLite Database browser" (that is able to open the database and execute the query) has no way to export it; SQLiteSpy will not open the database because it is compiled with a new SQLIte library version Maybe I can try to find an older version of SQLiteSpy on my archives, but I need more time for this... Thanks for the reply ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] newB question; c++ and sqlite3; how2 check if word exist in the table
it works fine! * This is what I thought you wanted. Using your table and column names my previous suggestion becomes: insert into tbl1 select 'seaside' where not exists (select words from tbl2 where words = 'seaside') The subselect will determine if the word is in tbl2 or not. If the word exists in tbl2, the subselect will return a row, so the where condition (not exists) on the select will be false, and the word will not be inserted into table tbl1. If the word doesn't exist in tbl2, the where condition will be true, and the word will be inserted into table tbl1. ** i wander is there a way to create combination of these 2 query: tbl1:word | number tbl2:word insert into tbl1 select 'seaside' where not exists (select words from tbl2 where words = 'seaside') and insert or replace into tbl1 values('seaside',coalesce ((select number from tbl1 where word = 'seaside') + 1, 1)); if there is 'seaside' in tbl2 nothing should be done, but if there is not seaside should be put into tbl1 and counter should increase i am sorry if i am annoying, i suppose that this question should solve this prob.. also i shall learn about databases a lot in the future so maybe i post more questions in future :) -- View this message in context: http://www.nabble.com/newB-question--c%2B%2B-and-sqlite3--how2-check-if-word-exist-in-the-table-tp15758100p16118115.html Sent from the SQLite mailing list archive at Nabble.com. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Database Table corrupt in SQLite v 3.4.0
> Do you test for SQLITE_BUSY, when you perform BEGIN IMMEDIATE ? > Yes, I do. > Yes a process that is reading will continue to read. Once it completes if > anothre process is waiting to write then the additional read locks will not be > granted. This is to prevent writer starvation. > > How do you know that the data for which you are querying is actually loaded? I > don't think you can since you invoke a load process after the query. > I query for updated data only after the writer process is terminated. --- Robosoft Technologies - Come home to Technology Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
Re: [sqlite] Database Table corrupt in SQLite v 3.4.0
> Where do the and come from? > Where do the and come from? > Where does all the data to create the new records come from? You say > Process A only has a FilePath as input. > Where do the and come from? > All the Information written into the database is extracted from the file itself. The Segments data is also available within the file itself. We manually append these information when we save the file. > What do you mean by the line that says "Info Values)"? > It is just the information retrieved from file. > > It seems strange to change the creation date for an update. I would > think this should only happen when the record is created in step d. Yes. Can't imagine how did I do this silly thing. > Where is this "set of files" coming from? The query in step a returns > results for a single file only. Process A takes a FilePath parameter, > the same as used in the where clause in query above I would assume. >> "SELECT * FROM Segments,File WHERE File.FileID = Segments.FileID AND >> File.FullPath = ; >> > > This will return the primary key for each segment associated with the > file. With that you can get any other info about the segment that may be > needed. Yes, that is what I need. I require all the information matching the given file. >> >> C) Repeat Step a) >> > > This is where you say you are having problems, correct? Are you saying > that you are not getting the same segments for the file FileA after > running process A with a parameter value of FileA? > > This is unexpected since you say Process A only updates existing rows if > the file FileA exists. It only adds new rows if FileA doesn't exist. But > if FileA doesn't exist when you run Process A then there would have been > nothing to return from the query in step a above, so any new rows would > be expected. If the file exists, then you update some column values, but > not the values that are used to select the results in the query in step > a above, so the results should be the same. > > Is there more stuff happening elsewhere that you haven't described? Are > the file and/or segment rows ever deleted? > Yes, the segments rows which are not updated are also deleted. This happens only when I do some large inserts/updates continuously i.e add/update file info and request for the updated as well as old data. I think there is some concurrency issues at my side. Now I have to re-visit to in what order are these inserts & selects are performed actually. > Process A knows it will write later, so the reserved lock at step a lets > others continue to read until it gets to step c or step d. The advantage > of this is that it prevents some other process form executing a delete > between your steps a and c for example. If the file existed when your > process A did its existence check as step a, but didn't exist when it > got to step c, there would be problems (not the problems you are seeing > though). It is probably a good idea to acquire the lock (i.e. start the > immediate transaction) before you start reading the database though. Just I tried to have an EXCLUSIVE lock in Process A just to ensure that writer process doesn't have to wait for reader process, and from that time onwards I am not getting this issue, atleast till now. But I cannot sign it off, treating this as the required change. Will look exactly what is happening. Since I am seeing this problem after upgrading it to 3.4.0, I thought its better to ask the list whether there were any known issues regarding database corrupt. Thanks for all your inputs, Will feedback what exactly is the case after I fix it, so that another person will get to know if he encounter with similar issue. -- Bharath On 3/18/08 12:59 AM, "Dennis Cote" <[EMAIL PROTECTED]> wrote: --- Robosoft Technologies - Come home to Technology Disclaimer: This email may contain confidential material. If you were not an intended recipient, please notify the sender and delete all copies. Emails to and from our network may be logged and monitored. This email and its attachments are scanned for virus by our scanners and are believed to be safe. However, no warranty is given that this email is free of malicious content or virus. ___ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users