DoSQL

From HyPhy Wiki
Jump to: navigation, search


DoSQL is a function used for interacting with a SQLite database.

Contents

Syntax

 DoSQL (database_id,action string|file name,<callback_id>);
 
 DoSQL (SQL_OPEN,path_to_database_file,database_id);
 
 DoSQL (database_id, <statement>, <callback_id>);
 
 DoSQL (SQL_CLOSE, '', database_id);

Parameters

  • database_id : The handler for the database. This is initialized when DoSQL(SQL_OPEN,path_to_database_file,database_id); is called.
  • action : The action you would like to like to do. Choices are SQL_OPEN and SQL_CLOSE
  • file_name : The file name of the sqlite database
  • callback_id : The callback function that you would like to call for each row returned

Environment Variables

  • SQL_ROW_DATA : This environment variable is populated when a statement is made with DoSQL. It contains an array of the data returned by the query.
  • SQL_COLUMN_NAMES : This environment variable is populated when a statement is made with DoSQL. It is an array of the column names in the table queried.

Examples

The following prints out the contents of the first column in each row returned, and then prints the column names returned in the query.

function printRowResult(dummy) 
{                              
   fprintf(stdout, SQL_ROW_DATA[0],"\n");
   return 0;
} 
 
dbpath="/path/to/sqlite/file";
DoSQL ( SQL_OPEN, dbpath, DBID );
DoSQL ( DBID, "SELECT * FROM column_name", "return printRowResult(0)");
fprintf( stdout, SQL_COLUMN_NAMES );
DoSQL ( SQL_CLOSE, "", DBID );
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox