Re: [sqlite] How to create a database in run-time

2008-01-22 Thread Dennis Cote

Luis Esteban Fajardo Bravo wrote:



my question is if there's a better solution for check if the database 
is already created, something like a "describe" SQL Command (in 
oracle) that help to know if the schema is already there on the database?




Luis,

You can use the pragma user_version command (see 
http://www.sqlite.org/pragma.html#version for detail). If you set the 
user version to some non-zero value when you initialize the database 
schema, then you can check for this condition as the first access of the 
database. In pseudo code you do this:


if (db_user_version == 0) {
   begin transaction
   initialize schema
   db_user_version = MY_VERSION;
   commit transaction
}

This will also allow you to check for and update older versions of your 
schema when you make changes.


HTH
Dennis Cote

-
To unsubscribe, send email to [EMAIL PROTECTED]
-



RE: [sqlite] How to create a database in run-time

2008-01-22 Thread Lee Crain

I'm not responding to your entire email, only the question far below.

On my employer's system, we use a query named "$CMD_ISDATABASECONSTRUCTED"
to check for whether the database is created. The query is simple:

"Analyze Categories;"


If the Categories table does not yet exist, the query fails.

If the Categories table already exists, the query succeeds.

This solution suffices for our needs.

Lee Crain

__ 


".my question is if there's a better solution for check if the
database is already created, something like a "describe" SQL Command (in
oracle) that help to know if the schema is already there on the database?"

Thank you!

--
---
To unsubscribe, send email to [EMAIL PROTECTED]
--
---


-
To unsubscribe, send email to [EMAIL PROTECTED]
-



Re: [sqlite] How to create a database in run-time

2008-01-21 Thread John Stanton

Luis Esteban Fajardo Bravo wrote:
Hi! we've using SQLite on our software since about a month ago, and 
still i have some questions about how does sqlite works at all.


I have the following sourcecode to check if a database is already 
created, if yes then just open, if not, open it and create the 
appropiate schema for the database:


if ( sqlite3_open_v2(path,,SQLITE_OPEN_READWRITE,NULL) != 
SQLITE_OK) {


   // Create the database

   sqlite3_close(historydb);

   if (sqlite3_open(path,) == SQLITE_OK) {

   // Now we create the default tables

   strcpy(query,"create table parameters (param_id integer 
primary key, param_name text(100));create table data_values (timestamp 
integer(4), value real, param_id integer(2));");


   rc = sqlite3_exec(historydb,query,process_query,NULL,);

   if (rc == SQLITE_OK) {

   strcpy(query,"pragma default_cache_size=40;");

   rc=sqlite3_exec(historydb,query,process_query,NULL,);

   }

   if (rc != SQLITE_OK) {

   // An error ocurred during database creation

  printf("SQL Error: ",errmsg);

   sqlite3_free(errmsg);

   return 0;

   }

   } else {

   // Unable to create database

  return 0;

   }

   }


This works fine under linux, and in windows if i run it onto gdb, but 
not if i call my object code from the command prompt, my question is if 
there's a better solution for check if the database is already created, 
something like a "describe" SQL Command (in oracle) that help to know if 
the schema is already there on the database?


Thank you!

You can use an "access" call to see if the file exists.  If you open it 
to test for existence you can do a "magic" test and look for the first 
few bytes being "SQLite" to authenticate it as an Sqlite DB.


- 


To unsubscribe, send email to [EMAIL PROTECTED]
- 






-
To unsubscribe, send email to [EMAIL PROTECTED]
-



[sqlite] How to create a database in run-time

2008-01-21 Thread Luis Esteban Fajardo Bravo
Hi! we've using SQLite on our software since about a month ago, and 
still i have some questions about how does sqlite works at all.


I have the following sourcecode to check if a database is already 
created, if yes then just open, if not, open it and create the 
appropiate schema for the database:


if ( sqlite3_open_v2(path,,SQLITE_OPEN_READWRITE,NULL) != SQLITE_OK) {

   // Create the database

   sqlite3_close(historydb);

   if (sqlite3_open(path,) == SQLITE_OK) {

   // Now we create the default tables

   strcpy(query,"create table parameters (param_id integer primary key, 
param_name text(100));create table data_values (timestamp integer(4), value real, 
param_id integer(2));");

   rc = sqlite3_exec(historydb,query,process_query,NULL,);

   if (rc == SQLITE_OK) {

   strcpy(query,"pragma default_cache_size=40;");

   rc=sqlite3_exec(historydb,query,process_query,NULL,);

   }

   if (rc != SQLITE_OK) {

   // An error ocurred during database creation

  printf("SQL Error: ",errmsg);

   sqlite3_free(errmsg);

   return 0;

   }

   } else {

   // Unable to create database

  return 0;

   }

   }


This works fine under linux, and in windows if i run it onto gdb, but 
not if i call my object code from the command prompt, my question is if 
there's a better solution for check if the database is already created, 
something like a "describe" SQL Command (in oracle) that help to know if 
the schema is already there on the database?


Thank you!

-
To unsubscribe, send email to [EMAIL PROTECTED]
-