/* Generated from "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod" by precompile.pike running Pike v8.0 release 1017
 *
 * Do NOT edit this file.
 */

#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 6

#undef PRECOMPILE_SUB_PIKEVARS
#define PRECOMPILE_SUB_PIKEVARS 1

#undef PRECOMPILE_DYNAMIC_TYPES
#define PRECOMPILE_DYNAMIC_TYPES 1



#undef cmod___CMOD__
#define cmod___CMOD__ 1
#line 1 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#line 3003 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"







#line 3010 "/Users/hww3/devel/pike/lib/modules/Tools.pmod/Standalone.pmod/precompile.pike"
#line 1 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#line 1 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
/* -*- c -*-
|| This file is part of Pike. For copyright information see COPYRIGHT.
|| Pike is distributed under GPL, LGPL and MPL. See the file COPYING
|| for more information.
*/

#include "global.h"
#include "interpret.h"
#include "backend.h"
#include "module_support.h"
#include "config.h"
#include "object.h"
#include "builtin_functions.h"
#include "mapping.h"
#include "threads.h"
#include "bignum.h"
#include "pike_types.h"
#include "multiset.h"

#if defined(HAVE_SQLITE3_H) && defined(HAVE_LIBSQLITE3)

#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif

#ifdef HAVE_WINDOWS_H
#include <windows.h>
#endif

#include <sqlite3.h>
#include <time.h>

#define SLEEP() sysleep(0.0001)



#ifndef PIKE_UNUSED_ATTRIBUTE
#define PIKE_UNUSED_ATTRIBUTE
#endif
#define CMOD_MAP_PROGRAM_IDS_DEFINED 1
static int ___cmod_map_program_ids(int id) PIKE_UNUSED_ATTRIBUTE;
#ifndef TYPEOF
/* Compat with older Pikes. */
#define TYPEOF(SVAL)	((SVAL).type)
#define SUBTYPEOF(SVAL)	((SVAL).subtype)
#define SET_SVAL_TYPE(SVAL, TYPE)	(TYPEOF(SVAL) = TYPE)
#define SET_SVAL_SUBTYPE(SVAL, TYPE)	(SUBTYPEOF(SVAL) = TYPE)
#define SET_SVAL(SVAL, TYPE, SUBTYPE, FIELD, EXPR) do {	\
    /* Set the type afterwards to avoid a clobbered	\
     * svalue in case EXPR throws. */			\
    (SVAL).u.FIELD = (EXPR);				\
    SET_SVAL_TYPE((SVAL), (TYPE));			\
    SET_SVAL_SUBTYPE((SVAL), (SUBTYPE));		\
  } while(0)
#endif /* !TYPEOF */
#ifndef PIKE_UNUSED
/* Compat with Pike 7.8 and earlier. */
/* NB: Not strictly correct; PIKE_UNUSED was added the
 *     day after set_program_id_to_id(), but good enough.
 */
#ifndef UNUSED
#define UNUSED(X)	X
#endif
#ifndef set_program_id_to_id
/* NB: Recent Pike 7.8 has a #define that conflicts with
 *     the following declaration.
 */
static void set_program_id_to_id(void*UNUSED(id)){}
#endif
#else /* */
PMOD_EXPORT void set_program_id_to_id( int (*to)(int) );
#endif /* !PIKE_UNUSED */


#ifndef DEFAULT_CMOD_STORAGE
#define CMOD_COND_USED
#define DEFAULT_CMOD_STORAGE static
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_ResObj_create_fun_num_used 1
#else
#define f_SQLite_ResObj_create_fun_num_used 1
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_ResObj_eof_fun_num_used 1
#else
#undef f_SQLite_ResObj_eof_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define SQLite_ResObj_program_fun_num_used 1
#else
#undef SQLite_ResObj_program_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_ResObj_seek_fun_num_used 1
#else
#undef f_SQLite_ResObj_seek_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_query_fun_num_used 1
#else
#undef f_SQLite_query_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_create_fun_num_used 1
#else
#undef f_SQLite_create_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_big_query_fun_num_used 1
#else
#undef f_SQLite_big_query_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_changes_fun_num_used 1
#else
#undef f_SQLite_changes_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_total_changes_fun_num_used 1
#else
#undef f_SQLite_total_changes_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_interrupt_fun_num_used 1
#else
#undef f_SQLite_interrupt_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_server_info_fun_num_used 1
#else
#undef f_SQLite_server_info_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_insert_id_fun_num_used 1
#else
#undef f_SQLite_insert_id_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_error_fun_num_used 1
#else
#undef f_SQLite_error_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_select_db_fun_num_used 1
#else
#undef f_SQLite_select_db_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_create_db_fun_num_used 1
#else
#undef f_SQLite_create_db_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_drop_db_fun_num_used 1
#else
#undef f_SQLite_drop_db_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_list_dbs_fun_num_used 1
#else
#undef f_SQLite_list_dbs_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define SQLite_program_fun_num_used 1
#else
#undef SQLite_program_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_ResObj_num_fields_fun_num_used 1
#else
#undef f_SQLite_ResObj_num_fields_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_ResObj_num_rows_fun_num_used 1
#else
#undef f_SQLite_ResObj_num_rows_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_ResObj_fetch_fields_fun_num_used 1
#else
#undef f_SQLite_ResObj_fetch_fields_fun_num_used
#endif
#ifndef CMOD_COND_USED
# define f_SQLite_ResObj_fetch_row_fun_num_used 1
#else
#undef f_SQLite_ResObj_fetch_row_fun_num_used
#endif
#line 41 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#define ERR(X, db)				\
if((X)!=SQLITE_OK) {				\
  SQLite_handle_error((db));			\
}

static void SQLite_handle_error(sqlite3 *db)
{
if (db) {
push_text(sqlite3_errmsg(db));
f_utf8_to_string(1);
Pike_error("Sql.SQLite: %S\n", Pike_sp[-1].u.string);
} else {
Pike_error("Sql.SQLite: Internal module error\n");
}
}

static int step(sqlite3_stmt *stmt) {
int ret;
/* FIXME: This is not always a good way to handle SQLITE_BUSY:
   *
   *   SQLITE_BUSY means that the database engine was unable to
   *   acquire the database locks it needs to do its job. If the
   *   statement is a COMMIT or occurs outside of an explicit
   *   transaction, then you can retry the statement. If the statement
   *   is not a COMMIT and occurs within a explicit transaction then
   *   you should rollback the transaction before continuing.
   */
while( (ret=sqlite3_step(stmt))==SQLITE_BUSY ) {
THREADS_ALLOW();
SLEEP();
THREADS_DISALLOW();
}
return ret;
}

/* NOTE: SQLite is flexible about the data stored within any field 
    and as such, any field in any row may hold any type of data, 
    regardless of the field's definition. Thus, when using bindings,
    this module will use the datatype of the value to determine the
    type stored in the field: ints and floats as numbers, strings as
    text. Binary (blob) data may be stored by wrapping the string
    containing the binary data in a multiset. For example:
    (< "some binary value">).
*/
static void bind_arguments(sqlite3 *db,
sqlite3_stmt *stmt,
struct mapping *bindings) {
struct mapping_data *md = bindings->data;
INT32 e;
struct keypair *k;
NEW_MAPPING_LOOP(md) {
int idx;
switch(TYPEOF(k->ind)) {
case T_INT:
idx = k->ind.u.integer;
break;
case T_STRING:
ref_push_string(k->ind.u.string);
f_string_to_utf8(1);
idx = sqlite3_bind_parameter_index(stmt, Pike_sp[-1].u.string->str);
pop_stack();
if(!idx)
Pike_error("Unknown bind index \"%S\".\n", k->ind.u.string);
break;
default:
Pike_error("Bind index is not int|string.\n");
}
switch(TYPEOF(k->val)) {
case T_INT:
ERR( sqlite3_bind_int64(stmt, idx, k->val.u.integer),
db );
break;
case T_STRING:
{
struct pike_string *s = k->val.u.string;
ref_push_string(s);
f_string_to_utf8(1);
s = Pike_sp[-1].u.string;
ERR( sqlite3_bind_text(stmt, idx, s->str, s->len,
SQLITE_TRANSIENT),
db);
pop_stack();
}
break;
case T_FLOAT:
ERR( sqlite3_bind_double(stmt, idx, (double)k->val.u.float_number),
db);
break;

case T_MULTISET:
if(multiset_sizeof(k->val.u.multiset) == 1) {
struct pike_string *s;
{
struct svalue tmp;
if (TYPEOF(*use_multiset_index (k->val.u.multiset,
multiset_first (k->val.u.multiset),
tmp)) == T_STRING)
s = tmp.u.string;
else
s = NULL;
}
if(s) {
ERR(sqlite3_bind_blob(stmt, idx, s->str, s->len,
SQLITE_STATIC),
db);
break;
}
}
/* Fallthrough */

default:
Pike_error("Can only bind string|int|float or single-valued multiset as blob.\n");
}
}
}

/*! @class SQLite
 *! @appears predef::Sql.sqlite
 *!
 *! Low-level interface to SQLite3 databases.
 *!
 *! This class should typically not be accessed directly, but instead
 *! via @[Sql.Sql()] with the scheme @expr{"sqlite://"@}.
 */


#undef class_SQLite_defined
#define class_SQLite_defined
DEFAULT_CMOD_STORAGE struct program *SQLite_program=NULL;

#ifdef SQLite_program_fun_num_used
DEFAULT_CMOD_STORAGE int SQLite_program_fun_num=-1;
#endif /* SQLite_program_fun_num_used */

#undef var_db_SQLite_defined
#define var_db_SQLite_defined

#undef THIS
#define THIS ((struct SQLite_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_SQLITE
#define THIS_SQLITE ((struct SQLite_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_SQLITE
#define OBJ2_SQLITE(o) ((struct SQLite_struct *)(o->storage+SQLite_storage_offset))

#undef GET_SQLITE_STORAGE
#define GET_SQLITE_STORAGE(o) ((struct SQLite_struct *)(o->storage+SQLite_storage_offset)
static ptrdiff_t SQLite_storage_offset;
struct SQLite_struct {

#ifdef var_db_SQLite_defined
#line 168 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
sqlite3 *db;
#endif /* var_db_SQLite_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct SQLite_struct *SQLite_gdb_dummy_ptr;
#endif
/*! @class ResObj
 *!
 *! Result object from @[big_query()].
 */


#undef class_SQLite_ResObj_defined
#define class_SQLite_ResObj_defined
DEFAULT_CMOD_STORAGE struct program *SQLite_ResObj_program=NULL;

#ifdef SQLite_ResObj_program_fun_num_used
DEFAULT_CMOD_STORAGE int SQLite_ResObj_program_fun_num=-1;
#endif /* SQLite_ResObj_program_fun_num_used */

#undef var_dbobj_SQLite_ResObj_defined
#define var_dbobj_SQLite_ResObj_defined

#undef var_bindings_SQLite_ResObj_defined
#define var_bindings_SQLite_ResObj_defined

#undef var_stmt_SQLite_ResObj_defined
#define var_stmt_SQLite_ResObj_defined

#undef var_eof_SQLite_ResObj_defined
#define var_eof_SQLite_ResObj_defined

#undef var_columns_SQLite_ResObj_defined
#define var_columns_SQLite_ResObj_defined

#undef THIS
#define THIS ((struct SQLite_ResObj_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef THIS_SQLITE_RESOBJ
#define THIS_SQLITE_RESOBJ ((struct SQLite_ResObj_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_SQLITE_RESOBJ
#define OBJ2_SQLITE_RESOBJ(o) ((struct SQLite_ResObj_struct *)(o->storage+SQLite_ResObj_storage_offset))

#undef GET_SQLITE_RESOBJ_STORAGE
#define GET_SQLITE_RESOBJ_STORAGE(o) ((struct SQLite_ResObj_struct *)(o->storage+SQLite_ResObj_storage_offset)
static ptrdiff_t SQLite_ResObj_storage_offset;
struct SQLite_ResObj_struct {

#ifdef var_dbobj_SQLite_ResObj_defined
#line 178 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct object *dbobj;
#endif /* var_dbobj_SQLite_ResObj_defined */

#ifdef var_bindings_SQLite_ResObj_defined
#line 179 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct mapping *bindings;
#endif /* var_bindings_SQLite_ResObj_defined */

#ifdef var_stmt_SQLite_ResObj_defined
#line 180 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
sqlite3_stmt *stmt;
#endif /* var_stmt_SQLite_ResObj_defined */

#ifdef var_eof_SQLite_ResObj_defined
#line 181 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
int eof;
#endif /* var_eof_SQLite_ResObj_defined */

#ifdef var_columns_SQLite_ResObj_defined
#line 182 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
int columns;
#endif /* var_columns_SQLite_ResObj_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct SQLite_ResObj_struct *SQLite_ResObj_gdb_dummy_ptr;
#endif
#line 184 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
static void ResObj_handle_error(void) {
Pike_error("Sql.SQLite: %s\n",
sqlite3_errmsg(OBJ2_SQLITE(THIS->dbobj)->db));
}

#define f_SQLite_ResObj_create_defined

#ifdef f_SQLite_ResObj_create_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_ResObj_create_fun_num = 0;

#endif /* f_SQLite_ResObj_create_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_ResObj_create(INT32 args) {
#line 189 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("create",args,0);
#line 191 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
THIS->columns = sqlite3_column_count(THIS->stmt);
}

}
/*! @decl int num_rows()
   *!
   *! @note
   *!   This API is not supported for @[Sql.sqlite].
   *!
   *! @seealso
   *!   @[Sql.sql_result()->num_rows()]
   */
#define f_SQLite_ResObj_num_rows_defined

#ifdef f_SQLite_ResObj_num_rows_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_ResObj_num_rows_fun_num = 0;

#endif /* f_SQLite_ResObj_num_rows_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_ResObj_num_rows(INT32 args) {
#line 203 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("num_rows",args,0);
#line 203 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
Pike_error("Sql.SQLite: Number of rows not known in advance.\n");
}

}
/*! @decl int num_fields()
   *!
   *! @seealso
   *!   @[Sql.sql_result()->num_fields()]
   */
#define f_SQLite_ResObj_num_fields_defined

#ifdef f_SQLite_ResObj_num_fields_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_ResObj_num_fields_fun_num = 0;

#endif /* f_SQLite_ResObj_num_fields_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_ResObj_num_fields(INT32 args) {
#line 212 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("num_fields",args,0);
#line 212 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
do { INT_TYPE ret_=(THIS->columns);  push_int(ret_); return; }while(0);
#line 214 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
}

}
/*! @decl int eof()
   *!
   *! @seealso
   *!   @[Sql.sql_result()->eof()]
   */
#define f_SQLite_ResObj_eof_defined

#ifdef f_SQLite_ResObj_eof_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_ResObj_eof_fun_num = 0;

#endif /* f_SQLite_ResObj_eof_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_ResObj_eof(INT32 args) {
#line 221 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("eof",args,0);
#line 221 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
do { INT_TYPE ret_=(THIS->eof);  push_int(ret_); return; }while(0);
#line 223 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
}

}
/*! @decl array(mapping(string:mixed)) fetch_fields()
   *!
   *! @seealso
   *!   @[Sql.sql_result()->fetch_fields()]
   */
#define f_SQLite_ResObj_fetch_fields_defined

#ifdef f_SQLite_ResObj_fetch_fields_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_ResObj_fetch_fields_fun_num = 0;

#endif /* f_SQLite_ResObj_fetch_fields_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_ResObj_fetch_fields(INT32 args) {
#line 230 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("fetch_fields",args,0);
#line 230 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
int i,t;
if (!sqlite3_column_name(THIS->stmt, 0)) {
/* Documented to happen on malloc() failure,
       * but can apparently happen in other cases too.
       * The common case seems to be when called after
       * the last row has been fetched.
       * Cf #10035.
       */
push_int(0);
return;
}
for(i=0; i<THIS->columns; i++) {
push_constant_text("name");
push_text(sqlite3_column_name(THIS->stmt, i));
f_utf8_to_string(1);
ref_push_string(literal_type_string);
t = sqlite3_column_type(THIS->stmt, i);
switch(t)
{
case SQLITE_INTEGER:
push_constant_text("integer");
break;
case SQLITE_FLOAT:
ref_push_string(literal_float_string);
break;
case SQLITE_BLOB:
push_constant_text("blob");
break;
case SQLITE_NULL:
push_constant_text("null");
break;
case SQLITE_TEXT:
push_constant_text("text");
break;
default:
push_text("unknown");
break;
}
f_aggregate_mapping(4);
}
f_aggregate(THIS->columns);
}

}
/*! @decl void seek(int skip)
   *!
   *! @seealso
   *!   @[Sql.sql_result()->seek()]
   */
#define f_SQLite_ResObj_seek_defined

#ifdef f_SQLite_ResObj_seek_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_ResObj_seek_fun_num = 0;

#endif /* f_SQLite_ResObj_seek_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_ResObj_seek(INT32 args) {
#line 279 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
INT_TYPE skip;
#line 279 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 1) wrong_number_of_args_error("seek",args,1);
#line 279 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("seek",1,"int");
#line 279 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
skip=Pike_sp[0-1].u.integer;
#line 279 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
int i;
for(i=0; i<skip; i++)
if( step(THIS->stmt)==SQLITE_DONE ) {
THIS->eof = 1;
return;
}
}

}
/*! @decl array fetch_row()
   *!
   *! @seealso
   *!   @[Sql.sql_result()->fetch_row()]
   */
#define f_SQLite_ResObj_fetch_row_defined

#ifdef f_SQLite_ResObj_fetch_row_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_ResObj_fetch_row_fun_num = 0;

#endif /* f_SQLite_ResObj_fetch_row_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_ResObj_fetch_row(INT32 args) {
#line 293 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("fetch_row",args,0);
#line 293 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
int i;
sqlite3_stmt *stmt = THIS->stmt;

if(THIS->eof) {
push_int(0);
return;
}

switch( step(stmt) ) {
case SQLITE_DONE:
THIS->eof = 1;
sqlite3_finalize(stmt);
THIS->stmt = 0;
push_int(0);
return;
case SQLITE_ROW:
break;
default:
ResObj_handle_error();
}

for(i=0; i<THIS->columns; i++) {
push_string( make_shared_binary_string
( sqlite3_column_blob(stmt, i),
sqlite3_column_bytes(stmt, i) ) );
if( sqlite3_column_type(stmt, i)==SQLITE_TEXT )
f_utf8_to_string(1);
}
f_aggregate(THIS->columns);
}

}

#undef internal_init_SQLite_ResObj_defined
#define internal_init_SQLite_ResObj_defined

#undef SQLite_ResObj_event_handler_defined
#define SQLite_ResObj_event_handler_defined
static void init_SQLite_ResObj_struct(void)
#line 325 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
THIS->eof = 0;
THIS->columns = -1;
THIS->dbobj = NULL;
THIS->stmt = NULL;
THIS->bindings = NULL;
}


#undef internal_exit_SQLite_ResObj_defined
#define internal_exit_SQLite_ResObj_defined

#undef SQLite_ResObj_event_handler_defined
#define SQLite_ResObj_event_handler_defined
static void exit_SQLite_ResObj_struct(void)
#line 335 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
if(THIS->stmt)
{
sqlite3_finalize(THIS->stmt);
THIS->stmt = NULL;
}
if(THIS->dbobj)
{
free_object(THIS->dbobj);
THIS->dbobj = NULL;
}
if(THIS->bindings)
{
free_mapping(THIS->bindings);
THIS->bindings = NULL;
}
}

#ifdef SQLite_ResObj_event_handler_defined
static void SQLite_ResObj_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_SQLite_ResObj_defined
  case PROG_EVENT_INIT: init_SQLite_ResObj_struct(); break;

#endif /* internal_init_SQLite_ResObj_defined */

#ifdef internal_exit_SQLite_ResObj_defined
  case PROG_EVENT_EXIT: exit_SQLite_ResObj_struct(); break;

#endif /* internal_exit_SQLite_ResObj_defined */
  default: break; 
  }
}

#endif /* SQLite_ResObj_event_handler_defined */
/*! @endclass
 */

#line 357 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#undef THIS
#define THIS THIS_SQLITE

/*! @decl void create(string path, mixed ... ignored)
   *!
   *! Open the SQLite database stored at @[path].
   */
#define f_SQLite_create_defined

#ifdef f_SQLite_create_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_create_fun_num = 0;

#endif /* f_SQLite_create_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_create(INT32 args) {
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct pike_string * path;
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct svalue * a;
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct svalue * b;
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct svalue * c;
struct mapping * options;
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args < 1) wrong_number_of_args_error("create",args,1);
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args > 5) wrong_number_of_args_error("create",args,5);
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create",1,"string");
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(path=Pike_sp[0-args].u.string);
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if ((args > 1) &&
    ((TYPEOF(Pike_sp[1-args]) != PIKE_T_INT) ||
     (SUBTYPEOF(Pike_sp[1-args]) != NUMBER_UNDEFINED))) {
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
a=Pike_sp+1-args; dmalloc_touch_svalue(Pike_sp+1-args);
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
} else a = NULL;
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if ((args > 2) &&
    ((TYPEOF(Pike_sp[2-args]) != PIKE_T_INT) ||
     (SUBTYPEOF(Pike_sp[2-args]) != NUMBER_UNDEFINED))) {
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
b=Pike_sp+2-args; dmalloc_touch_svalue(Pike_sp+2-args);
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
} else b = NULL;
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if ((args > 3) &&
    ((TYPEOF(Pike_sp[3-args]) != PIKE_T_INT) ||
     (SUBTYPEOF(Pike_sp[3-args]) != NUMBER_UNDEFINED))) {
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
c=Pike_sp+3-args; dmalloc_touch_svalue(Pike_sp+3-args);
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
} else c = NULL;
if (args > 4 &&
    (TYPEOF(Pike_sp[4-args]) != PIKE_T_INT ||
     Pike_sp[4-args].u.integer)) {
#line 365 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[4-args]) != PIKE_T_MAPPING) SIMPLE_ARG_TYPE_ERROR("create",5,"mapping(mixed:mixed)|void");
#line 365 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(options=Pike_sp[4-args].u.mapping);
#line 365 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
} else options = NULL;
#line 367 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
pop_n_elems(args-1);
f_string_to_utf8(1);
/* FIXME: Does the following work if THIS->db is already open? */
ERR( sqlite3_open(Pike_sp[-1].u.string->str, &THIS->db), THIS->db );
pop_stack();
}

}
/*! @decl array|int query(string query, @
   *!			    mapping(string|int:mixed)|void bindings)
   *!
   *! Perform a query against a SQLite database.
   *!
   *! @seealso
   *!   @[Sql.Sql()->query()]
   */
#define f_SQLite_query_defined

#ifdef f_SQLite_query_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_query_fun_num = 0;

#endif /* f_SQLite_query_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_query(INT32 args) {
#line 383 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct pike_string * query;
struct mapping * bindings;
#line 383 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args < 1) wrong_number_of_args_error("query",args,1);
#line 383 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args > 2) wrong_number_of_args_error("query",args,2);
#line 383 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("query",1,"string");
#line 383 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(query=Pike_sp[0-args].u.string);
if (args > 1 &&
    (TYPEOF(Pike_sp[1-args]) != PIKE_T_INT ||
     Pike_sp[1-args].u.integer)) {
#line 384 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_MAPPING) SIMPLE_ARG_TYPE_ERROR("query",2,"mapping(string|int:mixed)|void");
#line 384 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(bindings=Pike_sp[1-args].u.mapping);
#line 384 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
} else bindings = NULL;
#line 384 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{

sqlite3_stmt *stmt;
const char *tail;
struct pike_string *q;
INT32 res_count = 0;
INT32 columns;
INT32 i;

if(args==2) stack_swap();
f_string_to_utf8(1);
q = Pike_sp[-1].u.string;

ERR( sqlite3_prepare(THIS->db, q->str, q->len, &stmt, &tail),
THIS->db);
if( tail[0] )
Pike_error("Sql.SQLite->big_query: Trailing query data (\"%s\")\n",
tail);
pop_stack();


/* Add a reference to the database to prevent it from being
       destroyed before the query object. */

if(bindings) {
bind_arguments(THIS->db, stmt, bindings);
}

columns = sqlite3_column_count(stmt);

check_stack(128);

BEGIN_AGGREGATE_ARRAY(100) {
while(stmt) {

int sr=step(stmt);

switch(sr) {
case SQLITE_OK: /* Fallthrough */
case SQLITE_DONE:
sqlite3_finalize(stmt);
stmt = 0;
break;

case SQLITE_ROW:
for(i=0; i<columns; i++) {
push_text(sqlite3_column_name(stmt, i));
f_utf8_to_string(1);
push_string( make_shared_binary_string
( sqlite3_column_blob(stmt, i),
sqlite3_column_bytes(stmt, i) ) );
if( sqlite3_column_type(stmt, i)==SQLITE_TEXT )
f_utf8_to_string(1);
}
f_aggregate_mapping(columns*2);
DO_AGGREGATE_ARRAY(100);
break;

case SQLITE_MISUSE:
Pike_error("Sql.SQLite: Library misuse.");

default:
Pike_error("Sql.SQLite: (%d) %s\n", sr, sqlite3_errmsg(THIS->db));
}
}
} END_AGGREGATE_ARRAY;

if (!Pike_sp[-1].u.array->size && !columns) {
/* No rows and no columns. */
pop_stack();
push_int(0);
}
}

}
/*! @decl ResObj big_query(string query, @
   *!			     mapping(string|int:mixed)|void bindings)
   *!
   *! Perform a streaming query against a SQLite database.
   *!
   *! @seealso
   *!   @[Sql.Sql()->big_query()]
   */
#define f_SQLite_big_query_defined

#ifdef f_SQLite_big_query_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_big_query_fun_num = 0;

#endif /* f_SQLite_big_query_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_big_query(INT32 args) {
#line 466 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct pike_string * query;
struct mapping * bindings;
#line 466 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args < 1) wrong_number_of_args_error("big_query",args,1);
#line 466 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args > 2) wrong_number_of_args_error("big_query",args,2);
#line 466 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("big_query",1,"string");
#line 466 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(query=Pike_sp[0-args].u.string);
if (args > 1 &&
    (TYPEOF(Pike_sp[1-args]) != PIKE_T_INT ||
     Pike_sp[1-args].u.integer)) {
#line 467 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_MAPPING) SIMPLE_ARG_TYPE_ERROR("big_query",2,"mapping(string|int:mixed)|void");
#line 467 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(bindings=Pike_sp[1-args].u.mapping);
#line 467 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
} else bindings = NULL;
#line 467 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{

struct object *res;
sqlite3_stmt *stmt;
const char *tail;
struct SQLite_ResObj_struct *store;
struct pike_string *q;

if(args==2) stack_swap();
f_string_to_utf8(1);
q = Pike_sp[-1].u.string;

ERR( sqlite3_prepare(THIS->db, q->str, q->len, &stmt, &tail),
THIS->db);
if( tail[0] )
Pike_error("Sql.SQLite->big_query: Trailing query data (\"%s\")\n",
tail);
pop_stack();

res=fast_clone_object(SQLite_ResObj_program);
store = OBJ2_SQLITE_RESOBJ(res);
store->stmt = stmt;

/* Add a reference to the database to prevent it from being
       destroyed before the query object. */
store->dbobj = this_object();

if(bindings) {
bind_arguments(THIS->db, stmt, bindings);

/* Add a reference so that the bound strings are kept, which in
	 turn allows us to use SQLITE_STATIC. */
add_ref(bindings);
store->bindings = bindings;
}

apply_low(res, f_SQLite_ResObj_create_fun_num, 0);
push_object(res);
}

}
/*! @decl int changes()
   *!
   *! Get the number of changes.
   *!
   *! @fixme
   *!   Document this function properly.
   */
#define f_SQLite_changes_defined

#ifdef f_SQLite_changes_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_changes_fun_num = 0;

#endif /* f_SQLite_changes_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_changes(INT32 args) {
#line 514 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("changes",args,0);
#line 516 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
do { INT_TYPE ret_=(sqlite3_changes(THIS->db));  push_int(ret_); return; }while(0);
#line 518 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
}

}
/*! @decl int total_changes()
   *!
   *! Get the total number of changes for this session.
   *!
   *! @fixme
   *!   Document this function properly.
   */
#define f_SQLite_total_changes_defined

#ifdef f_SQLite_total_changes_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_total_changes_fun_num = 0;

#endif /* f_SQLite_total_changes_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_total_changes(INT32 args) {
#line 527 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("total_changes",args,0);
#line 529 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
do { INT_TYPE ret_=(sqlite3_total_changes(THIS->db));  push_int(ret_); return; }while(0);
#line 531 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
}

}
/*! @decl void interrupt()
   *!
   *! @fixme
   *!   Document this function.
   */
#define f_SQLite_interrupt_defined

#ifdef f_SQLite_interrupt_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_interrupt_fun_num = 0;

#endif /* f_SQLite_interrupt_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_interrupt(INT32 args) {
#line 538 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("interrupt",args,0);
#line 540 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
sqlite3_interrupt(THIS->db);
}

}
/*! @decl string server_info()
   *!
   *! Get information about the SQLite library version.
   *!
   *! @seealso
   *!   @[Sql.Sql()->server_info()]
   */
#define f_SQLite_server_info_defined

#ifdef f_SQLite_server_info_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_server_info_fun_num = 0;

#endif /* f_SQLite_server_info_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_server_info(INT32 args) {
#line 551 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("server_info",args,0);
#line 553 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
push_text(sqlite3_libversion());
}

}
/*! @decl int insert_id()
   *!
   *! Returns the value of the @tt{ROWID@} (aka @tt{OID@}, aka @tt{_ROWID_@},
   *! or declared @tt{INTEGER PRIMARY KEY@}) column for the most recent
   *! successful @tt{INSERT@} operation, or @expr{0@} (zero) if no @tt{INSERT@}
   *! operations have been performed on the connection yet.
   */
#define f_SQLite_insert_id_defined

#ifdef f_SQLite_insert_id_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_insert_id_fun_num = 0;

#endif /* f_SQLite_insert_id_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_insert_id(INT32 args) {
#line 564 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("insert_id",args,0);
#line 566 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
push_longest (sqlite3_last_insert_rowid(THIS->db));
}

}
/*! @decl string error()
   *!
   *! Get the latest error message.
   *!
   *! @seealso
   *!   @[Sql.Sql()->error()]
   */
#define f_SQLite_error_defined

#ifdef f_SQLite_error_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_error_fun_num = 0;

#endif /* f_SQLite_error_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_error(INT32 args) {
#line 577 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("error",args,0);
#line 579 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
push_text(sqlite3_errmsg(THIS->db));
f_utf8_to_string(1);
}

}
/*! @decl void select_db(string db)
   *!
   *! @note
   *!   This operation is not supported for SQLite.
   *!
   *! @seealso
   *!   @[Sql.Sql()->select_db()]
   */
#define f_SQLite_select_db_defined

#ifdef f_SQLite_select_db_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_select_db_fun_num = 0;

#endif /* f_SQLite_select_db_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_select_db(INT32 args) {
#line 592 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct pike_string * db;
#line 592 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 1) wrong_number_of_args_error("select_db",args,1);
#line 592 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("select_db",1,"string");
#line 592 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(db=Pike_sp[0-1].u.string);
#line 592 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
/* FIXME: This should be possible to support. */
Pike_error("This operation is not possible with SQLite.\n");
}

}
/*! @decl void create_db(string db)
   *!
   *! @note
   *!   This operation is not supported for SQLite.
   *!
   *! @seealso
   *!   @[Sql.Sql()->create_db()]
   */
#define f_SQLite_create_db_defined

#ifdef f_SQLite_create_db_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_create_db_fun_num = 0;

#endif /* f_SQLite_create_db_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_create_db(INT32 args) {
#line 605 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct pike_string * db;
#line 605 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 1) wrong_number_of_args_error("create_db",args,1);
#line 605 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create_db",1,"string");
#line 605 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(db=Pike_sp[0-1].u.string);
#line 605 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
/* FIXME: This should be possible to support. */
Pike_error("This operation is not possible with SQLite.\n");
}

}
/*! @decl void drop_db(string db)
   *!
   *! @note
   *!   This operation is not supported for SQLite.
   *!
   *! @seealso
   *!   @[Sql.Sql()->drop_db()]
   */
#define f_SQLite_drop_db_defined

#ifdef f_SQLite_drop_db_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_drop_db_fun_num = 0;

#endif /* f_SQLite_drop_db_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_drop_db(INT32 args) {
#line 618 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
struct pike_string * db;
#line 618 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 1) wrong_number_of_args_error("drop_db",args,1);
#line 618 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("drop_db",1,"string");
#line 618 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
debug_malloc_pass(db=Pike_sp[0-1].u.string);
#line 618 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
/* FIXME: This should be possible to support. */
Pike_error("This operation is not possible with SQLite.\n");
}

}
/*! @decl array(string) list_dbs()
   *!
   *! @note
   *!   This operation is not supported for SQLite.
   *!
   *! @seealso
   *!   @[Sql.Sql()->list_dbs()]
   */
#define f_SQLite_list_dbs_defined

#ifdef f_SQLite_list_dbs_fun_num_used
DEFAULT_CMOD_STORAGE ptrdiff_t f_SQLite_list_dbs_fun_num = 0;

#endif /* f_SQLite_list_dbs_fun_num_used */
DEFAULT_CMOD_STORAGE void f_SQLite_list_dbs(INT32 args) {
#line 631 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
if(args != 0) wrong_number_of_args_error("list_dbs",args,0);
#line 631 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
/* FIXME: This should be possible to support. */
/* SELECT name FROM sqlite_master ? */
Pike_error("This operation is not possible with SQLite.\n");
}

}

#undef internal_init_SQLite_defined
#define internal_init_SQLite_defined

#undef SQLite_event_handler_defined
#define SQLite_event_handler_defined
static void init_SQLite_struct(void)
#line 637 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
THIS->db = NULL;
}


#undef internal_exit_SQLite_defined
#define internal_exit_SQLite_defined

#undef SQLite_event_handler_defined
#define SQLite_event_handler_defined
static void exit_SQLite_struct(void)
#line 643 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
{
if(THIS->db) {
int i;
/* FIXME: sqlite3_close can fail. What do we do then? */
for(i=0; i<5; i++) {
if( sqlite3_close(THIS->db)!=SQLITE_OK ) {
THREADS_ALLOW();
SLEEP();
THREADS_DISALLOW();
} else break;
}
}
}


#ifdef SQLite_event_handler_defined
static void SQLite_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_SQLite_defined
  case PROG_EVENT_INIT: init_SQLite_struct(); break;

#endif /* internal_init_SQLite_defined */

#ifdef internal_exit_SQLite_defined
  case PROG_EVENT_EXIT: exit_SQLite_struct(); break;

#endif /* internal_exit_SQLite_defined */
  default: break; 
  }
}

#endif /* SQLite_event_handler_defined */
/*! @endclass
 */

#line 662 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#endif /* HAVE_SQLITE3_H && HAVE_LIBSQLITE3 */

PIKE_MODULE_INIT {

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
set_program_id_to_id( ___cmod_map_program_ids );

#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */

#ifdef class_SQLite_defined

#ifdef PROG_SQLITE_ID
#line 166 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  START_NEW_PROGRAM_ID(SQLITE);
#else
#line 166 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  start_new_program();

#endif /* PROG_SQLITE_ID */
#line 166 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  SQLite_program = Pike_compiler->new_program;

#ifndef tObjImpl_SQLITE

#undef tObjIs_SQLITE
#define tObjIs_SQLITE "\3\1\177\0\0\2"

#undef tObjImpl_SQLITE
#define tObjImpl_SQLITE "\3\0\177\0\0\2"

#endif /* tObjImpl_SQLITE */

#ifdef THIS_SQLITE
  SQLite_storage_offset = ADD_STORAGE(struct SQLite_struct);
#endif /* THIS_SQLITE */

#ifdef class_SQLite_ResObj_defined

#ifdef PROG_SQLITE_RESOBJ_ID
#line 175 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  START_NEW_PROGRAM_ID(SQLITE_RESOBJ);
#else
#line 175 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  start_new_program();

#endif /* PROG_SQLITE_RESOBJ_ID */
#line 175 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  SQLite_ResObj_program = Pike_compiler->new_program;

#ifndef tObjImpl_SQLITE_RESOBJ

#undef tObjIs_SQLITE_RESOBJ
#define tObjIs_SQLITE_RESOBJ "\3\1\177\0\0\3"

#undef tObjImpl_SQLITE_RESOBJ
#define tObjImpl_SQLITE_RESOBJ "\3\0\177\0\0\3"

#endif /* tObjImpl_SQLITE_RESOBJ */

#ifdef THIS_SQLITE_RESOBJ
  SQLite_ResObj_storage_offset = ADD_STORAGE(struct SQLite_ResObj_struct);
#endif /* THIS_SQLITE_RESOBJ */

#ifdef SQLite_ResObj_event_handler_defined
  pike_set_prog_event_callback(SQLite_ResObj_event_handler);

#ifndef SQLite_ResObj_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* SQLite_ResObj_gc_live_obj */

#endif /* SQLite_ResObj_event_handler_defined */

#ifdef f_SQLite_ResObj_create_defined

#ifdef f_SQLite_ResObj_create_fun_num_used
  f_SQLite_ResObj_create_fun_num =
#endif /* f_SQLite_ResObj_create_fun_num_used */
#line 189 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("create", f_SQLite_ResObj_create, tFunc(tNone,tVoid), ID_PROTECTED, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_ResObj_create_defined */

#ifdef f_SQLite_ResObj_num_rows_defined

#ifdef f_SQLite_ResObj_num_rows_fun_num_used
  f_SQLite_ResObj_num_rows_fun_num =
#endif /* f_SQLite_ResObj_num_rows_fun_num_used */
#line 203 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("num_rows", f_SQLite_ResObj_num_rows, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_ResObj_num_rows_defined */

#ifdef f_SQLite_ResObj_num_fields_defined

#ifdef f_SQLite_ResObj_num_fields_fun_num_used
  f_SQLite_ResObj_num_fields_fun_num =
#endif /* f_SQLite_ResObj_num_fields_fun_num_used */
    ADD_FUNCTION2("num_fields", f_SQLite_ResObj_num_fields, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_ResObj_num_fields_defined */

#ifdef f_SQLite_ResObj_eof_defined

#ifdef f_SQLite_ResObj_eof_fun_num_used
  f_SQLite_ResObj_eof_fun_num =
#endif /* f_SQLite_ResObj_eof_fun_num_used */
    ADD_FUNCTION2("eof", f_SQLite_ResObj_eof, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_ResObj_eof_defined */

#ifdef f_SQLite_ResObj_fetch_fields_defined

#ifdef f_SQLite_ResObj_fetch_fields_fun_num_used
  f_SQLite_ResObj_fetch_fields_fun_num =
#endif /* f_SQLite_ResObj_fetch_fields_fun_num_used */
    ADD_FUNCTION2("fetch_fields", f_SQLite_ResObj_fetch_fields, tFunc(tNone,tArr(tMap(tStr,tMix))), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_ResObj_fetch_fields_defined */

#ifdef f_SQLite_ResObj_seek_defined

#ifdef f_SQLite_ResObj_seek_fun_num_used
  f_SQLite_ResObj_seek_fun_num =
#endif /* f_SQLite_ResObj_seek_fun_num_used */
#line 279 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("seek", f_SQLite_ResObj_seek, tFunc("\10\200\0\0\0\177\377\377\377",tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_ResObj_seek_defined */

#ifdef f_SQLite_ResObj_fetch_row_defined

#ifdef f_SQLite_ResObj_fetch_row_fun_num_used
  f_SQLite_ResObj_fetch_row_fun_num =
#endif /* f_SQLite_ResObj_fetch_row_fun_num_used */
#line 293 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("fetch_row", f_SQLite_ResObj_fetch_row, tFunc(tNone,tArray), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_ResObj_fetch_row_defined */
#line 175 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  SQLite_ResObj_program=end_program();
#line 175 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#ifdef SQLite_ResObj_program_fun_num_used
SQLite_ResObj_program_fun_num=
#endif
 add_program_constant("ResObj",SQLite_ResObj_program,ID_PRIVATE | ID_PROTECTED | ID_HIDDEN);

#endif /* class_SQLite_ResObj_defined */

#ifdef SQLite_event_handler_defined
  pike_set_prog_event_callback(SQLite_event_handler);

#ifndef SQLite_gc_live_obj
  Pike_compiler->new_program->flags &= ~PROGRAM_LIVE_OBJ;

#endif /* SQLite_gc_live_obj */

#endif /* SQLite_event_handler_defined */

#ifdef f_SQLite_create_defined

#ifdef f_SQLite_create_fun_num_used
  f_SQLite_create_fun_num =
#endif /* f_SQLite_create_fun_num_used */
#line 364 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("create", f_SQLite_create, tFunc(tStr tOr(tMix,tVoid) tOr(tMix,tVoid) tOr(tMix,tVoid) tOr(tMapping,tVoid),tVoid), ID_PROTECTED, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_create_defined */

#ifdef f_SQLite_query_defined

#ifdef f_SQLite_query_fun_num_used
  f_SQLite_query_fun_num =
#endif /* f_SQLite_query_fun_num_used */
#line 383 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("query", f_SQLite_query, tFunc(tStr tOr(tMap(tOr(tStr,"\10\200\0\0\0\177\377\377\377"),tMix),tVoid),tOr(tArray,"\10\200\0\0\0\177\377\377\377")), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_query_defined */

#ifdef f_SQLite_big_query_defined

#ifdef f_SQLite_big_query_fun_num_used
  f_SQLite_big_query_fun_num =
#endif /* f_SQLite_big_query_fun_num_used */
#line 466 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("big_query", f_SQLite_big_query, tFunc(tStr tOr(tMap(tOr(tStr,"\10\200\0\0\0\177\377\377\377"),tMix),tVoid),tObj), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_big_query_defined */

#ifdef f_SQLite_changes_defined

#ifdef f_SQLite_changes_fun_num_used
  f_SQLite_changes_fun_num =
#endif /* f_SQLite_changes_fun_num_used */
#line 514 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("changes", f_SQLite_changes, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND);

#endif /* f_SQLite_changes_defined */

#ifdef f_SQLite_total_changes_defined

#ifdef f_SQLite_total_changes_fun_num_used
  f_SQLite_total_changes_fun_num =
#endif /* f_SQLite_total_changes_fun_num_used */
#line 527 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("total_changes", f_SQLite_total_changes, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND);

#endif /* f_SQLite_total_changes_defined */

#ifdef f_SQLite_interrupt_defined

#ifdef f_SQLite_interrupt_fun_num_used
  f_SQLite_interrupt_fun_num =
#endif /* f_SQLite_interrupt_fun_num_used */
#line 538 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("interrupt", f_SQLite_interrupt, tFunc(tNone,tVoid), 0, OPT_SIDE_EFFECT);

#endif /* f_SQLite_interrupt_defined */

#ifdef f_SQLite_server_info_defined

#ifdef f_SQLite_server_info_fun_num_used
  f_SQLite_server_info_fun_num =
#endif /* f_SQLite_server_info_fun_num_used */
#line 551 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("server_info", f_SQLite_server_info, tFunc(tNone,tStr), 0, OPT_TRY_OPTIMIZE);

#endif /* f_SQLite_server_info_defined */

#ifdef f_SQLite_insert_id_defined

#ifdef f_SQLite_insert_id_fun_num_used
  f_SQLite_insert_id_fun_num =
#endif /* f_SQLite_insert_id_fun_num_used */
#line 564 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("insert_id", f_SQLite_insert_id, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND);

#endif /* f_SQLite_insert_id_defined */

#ifdef f_SQLite_error_defined

#ifdef f_SQLite_error_fun_num_used
  f_SQLite_error_fun_num =
#endif /* f_SQLite_error_fun_num_used */
#line 577 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("error", f_SQLite_error, tFunc(tNone,tStr), 0, OPT_EXTERNAL_DEPEND);

#endif /* f_SQLite_error_defined */

#ifdef f_SQLite_select_db_defined

#ifdef f_SQLite_select_db_fun_num_used
  f_SQLite_select_db_fun_num =
#endif /* f_SQLite_select_db_fun_num_used */
#line 592 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("select_db", f_SQLite_select_db, tFunc(tStr,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_select_db_defined */

#ifdef f_SQLite_create_db_defined

#ifdef f_SQLite_create_db_fun_num_used
  f_SQLite_create_db_fun_num =
#endif /* f_SQLite_create_db_fun_num_used */
#line 605 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("create_db", f_SQLite_create_db, tFunc(tStr,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_create_db_defined */

#ifdef f_SQLite_drop_db_defined

#ifdef f_SQLite_drop_db_fun_num_used
  f_SQLite_drop_db_fun_num =
#endif /* f_SQLite_drop_db_fun_num_used */
#line 618 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("drop_db", f_SQLite_drop_db, tFunc(tStr,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_drop_db_defined */

#ifdef f_SQLite_list_dbs_defined

#ifdef f_SQLite_list_dbs_fun_num_used
  f_SQLite_list_dbs_fun_num =
#endif /* f_SQLite_list_dbs_fun_num_used */
#line 631 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    ADD_FUNCTION2("list_dbs", f_SQLite_list_dbs, tFunc(tNone,tArr(tStr)), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_SQLite_list_dbs_defined */
#line 166 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
  SQLite_program=end_program();
#line 166 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
#ifdef SQLite_program_fun_num_used
SQLite_program_fun_num=
#endif
 add_program_constant("SQLite",SQLite_program,0);

#endif /* class_SQLite_defined */

#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
set_program_id_to_id( 0 );
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
#line 665 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
;
}

PIKE_MODULE_EXIT {

#ifdef class_SQLite_defined

#ifdef class_SQLite_ResObj_defined
  if(SQLite_ResObj_program) {
#line 175 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    free_program(SQLite_ResObj_program);
    SQLite_ResObj_program=0;
  }

#endif /* class_SQLite_ResObj_defined */
  if(SQLite_program) {
#line 166 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
    free_program(SQLite_program);
    SQLite_program=0;
  }

#endif /* class_SQLite_defined */
#line 669 "/Users/hww3/devel/pike/src/post_modules/SQLite/sqlite.cmod"
;
}


#ifdef CMOD_MAP_PROGRAM_IDS_DEFINED
static int ___cmod_map_program_ids(int id)
{
  int i = 0;
  if( (id&0x7f000000) != 0x7f000000 ) return id;
  id = id&0x00ffffff;
#ifdef class_SQLite_defined
if(id==2) return SQLite_program->id;
#endif
#ifdef class_SQLite_ResObj_defined
if(id==3) return SQLite_ResObj_program->id;
#endif
  return 0;
}
#endif /* CMOD_MAP_PROGRAM_IDS_DEFINED */
