Home modules.gotpike.org
Username: Password: [Create Account]
[Forgot Password?]

Modules

ADT
Database
GTK2
GUI
IP
PiJAX
Public
Sql
Stdio
Subversion
System
Tools
Xosd
lua
v4l2
wx

Recent Changes

Public.Parser.XML2 1.50
Public.ZeroMQ 1.1
Public.Template.Mustache 1.0
Public.Protocols.XMPP 1.4
Sql.Provider.jdbc 1.0

Popular Downloads

Public.Parser.JSON2 1.0
Public.Parser.JSON 0.2
GTK2 2.23
Public.Web.FCGI 1.8
Public.Parser.XML2 1.48


Module Information
Database.EJDB
Viewing contents of Database_EJDB-1.1/ejdb.c

/* Generated from "ejdb.cmod" by precompile.pike
 *
 * Do NOT edit this file.
 */

#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 4



#undef cmod___CMOD__
#define cmod___CMOD__ 1
/*! @module Database
 */

/*! @module EJDB
 */

#line 7 "ejdb.cmod"
#define _GNU_SOURCE

#include "ejdb_config.h"
#include "util.h"

struct EJCOLL { /**> EJDB Collection. */
    char *cname; /**> Collection name. */
    int cnamesz; /**> Collection name length. */
    void *tdb; /**> Collection TCTDB. */
    void *jb; /**> Database handle. */
    void *mmtx; /*> Mutex for method */
};

#if HAVE_TCEJDB_EJDB_H
#include 
#endif /* HAVE_TCEJDB/EJDB_H */

extern struct program * EJDB_program;
struct program * Collection_program;

void lookup_collection_program();
void push_coll(EJCOLL * coll);
void throw_ejdb_error(struct object * db);
EJDB * getdb(struct object * db);



#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 DEFAULT_CMOD_STORAGE
#define DEFAULT_CMOD_STORAGE
#endif
/*! @class LowCollection
 */

#undef class_LowCollection_defined
#define class_LowCollection_defined
DEFAULT_CMOD_STORAGE struct program *LowCollection_program=NULL;
static int LowCollection_program_fun_num=-1;


#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 DEFAULT_CMOD_STORAGE
#define DEFAULT_CMOD_STORAGE
#endif

#undef var_coll_LowCollection_defined
#define var_coll_LowCollection_defined

#undef var_db_LowCollection_defined
#define var_db_LowCollection_defined

#undef var_name_LowCollection_defined
#define var_name_LowCollection_defined

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

#undef THIS_LOWCOLLECTION
#define THIS_LOWCOLLECTION ((struct LowCollection_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_LOWCOLLECTION
#define OBJ2_LOWCOLLECTION(o) ((struct LowCollection_struct *)(o->storage+LowCollection_storage_offset))

#undef GET_LOWCOLLECTION_STORAGE
#define GET_LOWCOLLECTION_STORAGE(o) ((struct LowCollection_struct *)(o->storage+LowCollection_storage_offset)
static ptrdiff_t LowCollection_storage_offset;
struct LowCollection_struct {

#ifdef var_coll_LowCollection_defined
#line 40 "ejdb.cmod"
EJCOLL * coll;
#endif /* var_coll_LowCollection_defined */

#ifdef var_db_LowCollection_defined
  struct object * db;

#endif /* var_db_LowCollection_defined */

#ifdef var_name_LowCollection_defined
  struct pike_string * name;

#endif /* var_name_LowCollection_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct LowCollection_struct *LowCollection_gdb_dummy_ptr;
#endif
#line 44 "ejdb.cmod"
#define COLL_DB(X) (EJDB *)(OBJ2_DB(X))
#define OBJ2_COLLECTION(X) ((struct LowCollection_struct *)get_storage(X, LowCollection_program))
#define THISLC ((struct LowCollection_struct *)get_storage(Pike_fp->current_object, LowCollection_program))
  #define f_LowCollection_create_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_create_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_create(INT32 args) {
#line 47 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("create",args,0);
{

  }
  
  }
#define f_LowCollection_cq__sprintf_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_cq__sprintf_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_cq__sprintf(INT32 args) {
#line 52 "ejdb.cmod"
struct svalue * format;
#line 52 "ejdb.cmod"
struct svalue * bar;
#line 52 "ejdb.cmod"
if(args != 2) wrong_number_of_args_error("_sprintf",args,2);
#line 52 "ejdb.cmod"
format=Pike_sp+0-2; dmalloc_touch_svalue(Pike_sp+0-2);
#line 52 "ejdb.cmod"
bar=Pike_sp+1-2; dmalloc_touch_svalue(Pike_sp+1-2);
{
    push_text("EJDB.Collection(");
    push_string(THISLC->name);
    f_add(2);
    push_text(")");
    f_add(2);
  }

  }
/*! @decl int delete(string oid)
   */
    #define f_LowCollection_delete_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_delete_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_delete_bson(INT32 args) {
#line 63 "ejdb.cmod"
struct pike_string * oid;
#line 63 "ejdb.cmod"
if(args != 1) wrong_number_of_args_error("delete_bson",args,1);
#line 63 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("delete_bson",1,"string");
#line 63 "ejdb.cmod"
debug_malloc_pass(oid=Pike_sp[0-1].u.string);
{
      bson_oid_t _oid;
      int ret;
      
      if(!THISLC->coll)
      {
        pop_n_elems(args);
        Pike_error("Collection not initialized properly.\n");
      }

      if(oid && !oid->len)
      {
        pop_n_elems(args);
        Pike_error("OID cannot be a zero-length string.\n");
      }

      bson_oid_from_string(&_oid, oid->str);

      if((ret = ejdbrmbson(THISLC->coll, &_oid)))
      {
        pop_stack();
        push_int(0);
      }
      else
      {
          int ecode = ejdbecode(getdb(THISLC->db)); 
  /*        printf("ecode: %d\n", ecode); */
          if (ecode != TCESUCCESS) {
          pop_stack();
    /*          printf("throwing error.\n"); */
              throw_ejdb_error(THISLC->db);
              }
      }
    }

    }
/*! @decl int set_index(string index, int flags)
     *! Set index for JSON field in EJDB collection.
     */
  #define f_LowCollection_set_index_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_set_index_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_set_index(INT32 args) {
#line 102 "ejdb.cmod"
struct pike_string * index;
#line 102 "ejdb.cmod"
INT_TYPE flags;
#line 102 "ejdb.cmod"
if(args != 2) wrong_number_of_args_error("set_index",args,2);
#line 102 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-2]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("set_index",1,"string");
#line 102 "ejdb.cmod"
debug_malloc_pass(index=Pike_sp[0-2].u.string);
#line 102 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-2]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("set_index",2,"int");
#line 102 "ejdb.cmod"
flags=Pike_sp[1-2].u.integer;
{
    int ret;

    if(!THISLC->coll)
    {
        pop_n_elems(args);
        Pike_error("Collection not initialized properly.\n");
    }
  
     ref_push_string(index);
     f_string_to_utf8(1);

     ret = ejdbsetindex(THISLC->coll, (const char *)(Pike_sp[-1].u.string->str), flags);
  
     pop_n_elems(args + 1);
     push_int(ret);
  }

  }
/*! @decl string load_bson(string oid)
   */
  #define f_LowCollection_load_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_load_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_load_bson(INT32 args) {
#line 123 "ejdb.cmod"
struct pike_string * oid;
#line 123 "ejdb.cmod"
if(args != 1) wrong_number_of_args_error("load_bson",args,1);
#line 123 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("load_bson",1,"string");
#line 123 "ejdb.cmod"
debug_malloc_pass(oid=Pike_sp[0-1].u.string);
{
    bson_oid_t _oid;
    bson * _bson;

    if(!THISLC->coll)
    {
      pop_n_elems(args);
      Pike_error("Collection not initialized properly.\n");
    }

    if(oid && !oid->len)
    {
      pop_n_elems(args);
      Pike_error("OID cannot be a zero-length string.\n");
    }

    bson_oid_from_string(&_oid, oid->str);

    if((_bson = ejdbloadbson(THISLC->coll, &_oid)))
    {
      struct pike_string * bsonStr;
/*      bson_print_raw(stdout, bson_data(_bson), 10); */
      bsonStr = make_shared_binary_string(bson_data(_bson), bson_size(_bson));
     /* bson_destroy(&_bson); */
      do { struct pike_string * ret_=(bsonStr); pop_stack(); push_string(ret_); return; }while(0);
#line 149 "ejdb.cmod"
}
    else
    {
        int ecode = ejdbecode(getdb(THISLC->db)); 
        if (ecode != TCESUCCESS) {
  pop_stack();
            throw_ejdb_error(THISLC->db);
            }
      pop_stack();
      push_int(0);
    }
  }

  }
/*! @decl string save_bson(string bsonval, string|void oid, int|void merge)
   */
  #define f_LowCollection_save_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_save_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_save_bson(INT32 args) {
#line 164 "ejdb.cmod"
struct pike_string * bsonval;
#line 164 "ejdb.cmod"
struct pike_string * oid;
#line 164 "ejdb.cmod"
struct svalue * merge;
#line 164 "ejdb.cmod"
if(args < 1) wrong_number_of_args_error("save_bson",args,1);
#line 164 "ejdb.cmod"
if(args > 3) wrong_number_of_args_error("save_bson",args,3);
#line 164 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("save_bson",1,"string");
#line 164 "ejdb.cmod"
debug_malloc_pass(bsonval=Pike_sp[0-args].u.string);
#line 164 "ejdb.cmod"
if (args > 1 &&    (TYPEOF(Pike_sp[1-args]) != PIKE_T_INT ||     Pike_sp[1-args].u.integer)) {
#line 164 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("save_bson",2,"string|void");
#line 164 "ejdb.cmod"
debug_malloc_pass(oid=Pike_sp[1-args].u.string);
#line 164 "ejdb.cmod"
} else oid = NULL;
#line 164 "ejdb.cmod"
if (args > 2) {
#line 164 "ejdb.cmod"
if(TYPEOF(Pike_sp[2-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("save_bson",3,"int|void");
#line 164 "ejdb.cmod"
merge=Pike_sp+2-args; dmalloc_touch_svalue(Pike_sp+2-args);
#line 164 "ejdb.cmod"
} else merge = NULL;
{
    bson_oid_t _oid;
    bson _bson;
    int _merge = 0;

    if(!THISLC->coll)
    {
      pop_n_elems(args);
      Pike_error("Collection not initialized properly.\n");
    }

    if(oid && !oid->len)
    {
      pop_n_elems(args);
      Pike_error("OID cannot be a zero-length string.\n");
    }
    else if(oid)
    {
      bson_oid_from_string(&_oid, oid->str);
    }

    if(merge->type == T_INT)
    {
      _merge = merge->u.integer;
    }

    bson_init_finished_data(&_bson, bsonval->str);
 /*   bson_print_raw(stdout, bson_data(&_bson), 10); */
    
    if(ejdbsavebson2(THISLC->coll, &_bson, &_oid, merge))
    {
      struct pike_string * oidStr;
      char c[24];
      bson_oid_to_string((const bson_oid_t *)&_oid, (char *)&c);

      oidStr = make_shared_binary_string(c, strlen(c));
      /*bson_destroy(&_bson); */
      do { struct pike_string * ret_=(oidStr); pop_n_elems(args); push_string(ret_); return; }while(0);
#line 203 "ejdb.cmod"
}
    else
    {
          int ecode = ejdbecode(getdb(THISLC->db)); 
          if (ecode != TCESUCCESS) {
            pop_stack();
              throw_ejdb_error(THISLC->db);
              }
    
      do { struct pike_string * ret_=(0); pop_n_elems(args); push_string(ret_); return; }while(0);
#line 213 "ejdb.cmod"
}

  }

  }
/*! @decl array low_find(string bson_query)
   */
  #define f_LowCollection_low_find_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_low_find_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_low_find(INT32 args) {
#line 219 "ejdb.cmod"
struct pike_string * bson_query;
#line 219 "ejdb.cmod"
struct pike_string * bson_hints;
#line 219 "ejdb.cmod"
struct svalue * flags;
#line 219 "ejdb.cmod"
if(args < 1) wrong_number_of_args_error("low_find",args,1);
#line 219 "ejdb.cmod"
if(args > 3) wrong_number_of_args_error("low_find",args,3);
#line 219 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("low_find",1,"string");
#line 219 "ejdb.cmod"
debug_malloc_pass(bson_query=Pike_sp[0-args].u.string);
#line 219 "ejdb.cmod"
if (args > 1 &&    (TYPEOF(Pike_sp[1-args]) != PIKE_T_INT ||     Pike_sp[1-args].u.integer)) {
#line 219 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("low_find",2,"string|void");
#line 219 "ejdb.cmod"
debug_malloc_pass(bson_hints=Pike_sp[1-args].u.string);
#line 219 "ejdb.cmod"
} else bson_hints = NULL;
#line 219 "ejdb.cmod"
if (args > 2) {
#line 219 "ejdb.cmod"
if(TYPEOF(Pike_sp[2-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("low_find",3,"int|void");
#line 219 "ejdb.cmod"
flags=Pike_sp+2-args; dmalloc_touch_svalue(Pike_sp+2-args);
#line 219 "ejdb.cmod"
} else flags = NULL;
{
    int _flags = 0;
    bson _bson;
    bson _hints;
    EJQ *q1;
    uint32_t count;
    TCLIST *res;
    int i;
    int havehints = 0;
    
    if(!THISLC->coll)
    {
      pop_n_elems(args);
      Pike_error("Collection not initialized properly.\n");
    }
    
    if(flags->type == T_INT)
     {
       _flags = flags->u.integer;
     }
    
    bson_init_finished_data(&_bson, bson_query->str);
    if(bson_hints)
    {
      havehints = 1;
      bson_init_finished_data(&_hints, bson_hints->str);
    }    
 /*  bson_print_raw(stdout, bson_data(&_bson), 10); */
    
    THREADS_ALLOW();
   if(havehints)
      q1 = ejdbcreatequery(getdb(THISLC->db), &_bson, NULL, 0, &_hints);
   else
     q1 = ejdbcreatequery(getdb(THISLC->db), &_bson, NULL, 0, NULL);
   
printf("coll: %p, %p, %p\n", getdb(THISLC->db), q1, THISLC->coll);
      res = ejdbqryexecute(THISLC->coll, q1, &count, _flags, NULL);
 /*   fprintf(stderr, "\n\nRecords found: %d\n", count); */
   THREADS_DISALLOW();

    pop_stack();

    /*Now print the result set records */
    for (i = 0; i < TCLISTNUM(res); ++i) {
    struct pike_string * bt;
      char *bsdata = (char *)TCLISTVALPTR(res, i);
      /* TODO: find a more efficient approach to this (as in, do we really need the length in order to make the pike_string?) */
      bson_init_finished_data(&_bson, bsdata);
/*      bson_print_raw(stderr, bsdata, 0); */
      
      bt = make_shared_binary_string(bson_data(&_bson), bson_size(&_bson));
      push_string(bt);
      }
    fprintf(stderr, "\n");
    f_aggregate(count);

    /*Dispose result set */
    tclistdel(res);

    /*Dispose query */
    ejdbquerydel(q1);
 /*   bson_destroy(&_bson); */
  }
  
  }
/*! @decl int begin_transaction()
   *! Begin transaction for EJDB collection.
   */
  #define f_LowCollection_begin_transaction_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_begin_transaction_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_begin_transaction(INT32 args) {
#line 287 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("begin_transaction",args,0);
{
    int ret;
    
    if(!THISLC->coll)
    {
        pop_n_elems(args);
        Pike_error("Collection not initialized properly.\n");
    }
    
    ret = ejdbtranbegin(THISLC->coll);
    
    push_int(ret);
  }

  }
/*! @decl int abort_transaction()
   *! Abort transaction for EJDB collection.
   */
  #define f_LowCollection_abort_transaction_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_abort_transaction_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_abort_transaction(INT32 args) {
#line 305 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("abort_transaction",args,0);
{
    int ret;
    
    if(!THISLC->coll)
    {
        pop_n_elems(args);
        Pike_error("Collection not initialized properly.\n");
    }
    
    ret = ejdbtranabort(THISLC->coll);
    
    push_int(ret);
  }

  }
/*! @decl int commit_transaction()
   *! Commit transaction for EJDB collection.
   */
  #define f_LowCollection_commit_transaction_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_commit_transaction_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_commit_transaction(INT32 args) {
#line 323 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("commit_transaction",args,0);
{
    int ret;
    
    if(!THISLC->coll)
    {
        pop_n_elems(args);
        Pike_error("Collection not initialized properly.\n");
    }
    
    ret = ejdbtrancommit(THISLC->coll);
    
    push_int(ret);
  }

  }
/*! @decl int transaction_status()
   *! Get current transaction status.
   */
  #define f_LowCollection_transaction_status_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_transaction_status_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_transaction_status(INT32 args) {
#line 341 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("transaction_status",args,0);
{
    bool ret;
    bool txstat;
    
    if(!THISLC->coll)
    {
        pop_n_elems(args);
        Pike_error("Collection not initialized properly.\n");
    }
    
    ret = ejdbtranstatus(THISLC->coll, &txstat);
    
    if(ret)
        push_int(txstat);
    else
        Pike_error("Error getting transaction status.\n");
  }
  
  }
/*! @decl int sync()
   *! Synchronize content of a EJDB collection database with the file on device.
   */
  #define f_LowCollection_sync_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_sync_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_sync(INT32 args) {
#line 363 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("sync",args,0);
{
     if (!ejdbsyncoll(THISLC->coll)) {
         do { INT_TYPE ret_=(ejdbecode(getdb(THISLC->db)));  push_int(ret_); return; }while(0);
#line 367 "ejdb.cmod"
}
     else do { INT_TYPE ret_=(0);  push_int(ret_); return; }while(0);
#line 369 "ejdb.cmod"
}
  

  }

#undef internal_init_LowCollection_defined
#define internal_init_LowCollection_defined

#undef LowCollection_event_handler_defined
#define LowCollection_event_handler_defined
static void init_LowCollection_struct(void)
#line 373 "ejdb.cmod"
{
  }

  
#undef LowCollection_gc_live_obj
#define LowCollection_gc_live_obj

#undef internal_exit_LowCollection_defined
#define internal_exit_LowCollection_defined

#undef LowCollection_event_handler_defined
#define LowCollection_event_handler_defined
static void exit_LowCollection_struct(void)
#line 377 "ejdb.cmod"
{
    if(THIS->db)
      free_object(THIS->db);
  }

#ifdef LowCollection_event_handler_defined
static void LowCollection_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_LowCollection_defined
  case PROG_EVENT_INIT: init_LowCollection_struct(); break;

#endif /* internal_init_LowCollection_defined */

#ifdef internal_exit_LowCollection_defined
  case PROG_EVENT_EXIT: exit_LowCollection_struct(); break;

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

#endif /* LowCollection_event_handler_defined */
/*! @endclass
 */

/*! @class Database
 */

#undef class_Database_defined
#define class_Database_defined
DEFAULT_CMOD_STORAGE struct program *Database_program=NULL;
static int Database_program_fun_num=-1;


#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 DEFAULT_CMOD_STORAGE
#define DEFAULT_CMOD_STORAGE
#endif

#undef var_jb_Database_defined
#define var_jb_Database_defined

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

#undef THIS_DATABASE
#define THIS_DATABASE ((struct Database_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_DATABASE
#define OBJ2_DATABASE(o) ((struct Database_struct *)(o->storage+Database_storage_offset))

#undef GET_DATABASE_STORAGE
#define GET_DATABASE_STORAGE(o) ((struct Database_struct *)(o->storage+Database_storage_offset)
static ptrdiff_t Database_storage_offset;
struct Database_struct {

#ifdef var_jb_Database_defined
#line 392 "ejdb.cmod"
EJDB * jb;
#endif /* var_jb_Database_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct Database_struct *Database_gdb_dummy_ptr;
#endif
/*! @decl void create(string dbpath, int flags)
 */
#define f_Database_create_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_create_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_create(INT32 args) {
#line 396 "ejdb.cmod"
struct pike_string * dbpath;
#line 396 "ejdb.cmod"
INT_TYPE flags;
#line 396 "ejdb.cmod"
if(args != 2) wrong_number_of_args_error("create",args,2);
#line 396 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-2]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create",1,"string");
#line 396 "ejdb.cmod"
debug_malloc_pass(dbpath=Pike_sp[0-2].u.string);
#line 396 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-2]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("create",2,"int");
#line 396 "ejdb.cmod"
flags=Pike_sp[1-2].u.integer;
{
  static EJDB *jb;
  jb = ejdbnew();
  if (!ejdbopen(jb, dbpath->str, flags)) {
    Pike_error("Unable to open database %s", dbpath->str);
  }
  pop_n_elems(args);
  
  THIS->jb = jb;
  /*printf("db: %p\n", THIS->jb); */
}

}
/*! @decl int sync()
 *! Synchronize entire EJDB database and all its collections with storage.
 */ 
#define f_Database_sync_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_sync_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_sync(INT32 args) {
#line 412 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("sync",args,0);
{
   if (!ejdbsyncdb(THIS->jb)) {
       do { INT_TYPE ret_=(ejdbecode(THIS->jb));  push_int(ret_); return; }while(0);
#line 416 "ejdb.cmod"
}
   else do { INT_TYPE ret_=(0);  push_int(ret_); return; }while(0);
#line 418 "ejdb.cmod"
}

}
/*! @decl int is_open()
 */
#define f_Database_is_open_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_is_open_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_is_open(INT32 args) {
#line 422 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("is_open",args,0);
{
   do { INT_TYPE ret_=((ejdbisopen(THIS->jb)));  push_int(ret_); return; }while(0);
#line 425 "ejdb.cmod"
}

}
/*! @decl int close()
 */
#define f_Database_close_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_close_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_close(INT32 args) {
#line 429 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("close",args,0);
{
   if (!ejdbclose(THIS->jb)) {
       do { INT_TYPE ret_=(ejdbecode(THIS->jb));  push_int(ret_); return; }while(0);
#line 433 "ejdb.cmod"
}
   else do { INT_TYPE ret_=(0);  push_int(ret_); return; }while(0);
#line 435 "ejdb.cmod"
}

}
/*! @decl int delete_collections(string collection, int unlink)
 *! Removes collections specified by 'name'.
 */
#define f_Database_delete_collection_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_delete_collection_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_delete_collection(INT32 args) {
#line 440 "ejdb.cmod"
struct pike_string * name;
#line 440 "ejdb.cmod"
INT_TYPE unlink;
#line 440 "ejdb.cmod"
if(args != 2) wrong_number_of_args_error("delete_collection",args,2);
#line 440 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-2]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("delete_collection",1,"string");
#line 440 "ejdb.cmod"
debug_malloc_pass(name=Pike_sp[0-2].u.string);
#line 440 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-2]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("delete_collection",2,"int");
#line 440 "ejdb.cmod"
unlink=Pike_sp[1-2].u.integer;
{
  int ret;
 
  ref_push_string(name);
  f_string_to_utf8(1);

  ret = ejdbrmcoll(THIS->jb, Pike_sp[-1].u.string->str, unlink);
  pop_n_elems(args + 1);
  
  push_int(ret);
} 

}
/*! @decl array(string) get_collections()
 */
#define f_Database_get_collections_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_get_collections_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_get_collections(INT32 args) {
#line 455 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("get_collections",args,0);
{
  TCLIST *colls;
  int i;
  struct pike_string * cn;

  colls = ejdbgetcolls(THIS->jb);
  
  for (i = 0; i < TCLISTNUM(colls); ++i) {
    EJCOLL *coll = (EJCOLL *)TCLISTVALPTR(colls, i);
    cn = make_shared_binary_string(coll->cname, coll->cnamesz);
    push_string(cn);
    f_utf8_to_string(1);
  }
  
  f_aggregate(TCLISTNUM(colls));

  /*Dispose result set */
  tclistdel(colls);
}

}
/*! @decl object get_collection(string name)
 */
#define f_Database_get_collection_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_get_collection_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_get_collection(INT32 args) {
#line 478 "ejdb.cmod"
struct pike_string * name;
#line 478 "ejdb.cmod"
if(args != 1) wrong_number_of_args_error("get_collection",args,1);
#line 478 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("get_collection",1,"string");
#line 478 "ejdb.cmod"
debug_malloc_pass(name=Pike_sp[0-1].u.string);
{
  EJCOLL* coll;
  
  ref_push_string(name);
  f_string_to_utf8(1);

  coll = ejdbgetcoll(THIS->jb, (Pike_sp[-1].u.string->str));

printf("coll: %p\n", coll);
  if(!coll)
  {
    pop_n_elems(args + 1);
    push_int(0);
    return;
  }
  else
  {
    pop_n_elems(args + 1);
    push_coll(coll);
    return;
  }
}

}
/*! @decl object create_collection(string name, mapping|void opts) 
  *! OPTIONS:
  *!large
  *!compressed
  *!records
  *!cachcedrecords
  */
#define f_Database_create_collection_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_Database_create_collection_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_Database_create_collection(INT32 args) {
#line 509 "ejdb.cmod"
struct pike_string * name;
#line 509 "ejdb.cmod"
struct mapping * opts;
#line 509 "ejdb.cmod"
if(args < 1) wrong_number_of_args_error("create_collection",args,1);
#line 509 "ejdb.cmod"
if(args > 2) wrong_number_of_args_error("create_collection",args,2);
#line 509 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create_collection",1,"string");
#line 509 "ejdb.cmod"
debug_malloc_pass(name=Pike_sp[0-args].u.string);
#line 509 "ejdb.cmod"
if (args > 1 &&    (TYPEOF(Pike_sp[1-args]) != PIKE_T_INT ||     Pike_sp[1-args].u.integer)) {
#line 509 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_MAPPING) SIMPLE_ARG_TYPE_ERROR("create_collection",2,"mapping(mixed:mixed)|void");
#line 509 "ejdb.cmod"
debug_malloc_pass(opts=Pike_sp[1-args].u.mapping);
#line 509 "ejdb.cmod"
} else opts = NULL;
{
  EJCOLL* coll;
  EJCOLLOPTS _opts;
  struct svalue * sv;

  ref_push_string(name);
  f_string_to_utf8(1);
  name = Pike_sp[0-1].u.string;

  if(opts)
  {
    sv = simple_mapping_string_lookup(opts, "large");
    
    if(sv && sv->type == T_INT)
    {
      _opts.large = (sv->u.integer?1:0);
    }
    
    sv = simple_mapping_string_lookup(opts, "compressed");

    if(sv && sv->type == T_INT)
    {
      _opts.compressed = (sv->u.integer?1:0);
    }

    sv = simple_mapping_string_lookup(opts, "records");

    if(sv && sv->type == T_INT)
    {
      _opts.records = (sv->u.integer);
    }

    sv = simple_mapping_string_lookup(opts, "cachedrecords");

    if(sv && sv->type == T_INT)
    {
      _opts.cachedrecords = (sv->u.integer?1:0);
    }
  }

  coll = ejdbcreatecoll(THIS->jb, (name->str), &_opts);
  if(!coll)
  {
    pop_n_elems(args + 1);
    push_int(0);
    return;
  }
  else
  {
    pop_n_elems(args + 1);
    push_coll(coll);
    return;
  }
}

}
#line 565 "ejdb.cmod"
#define OBJ2_COLLECTION(X) ((struct LowCollection_struct *)get_storage(X, LowCollection_program))

void push_coll(EJCOLL * coll)
{
  struct object * c;
  struct pike_string * name;
  if(!Collection_program)
    lookup_collection_program();
  c = clone_object(Collection_program, 0);
  name = make_shared_binary_string(coll->cname, coll->cnamesz);
  push_string(name);
  f_utf8_to_string(1);
  name = Pike_sp[-1].u.string;
  add_ref(name);
  pop_stack();
  OBJ2_COLLECTION(c)->coll = coll;
  OBJ2_COLLECTION(c)->db = this_object();
  OBJ2_COLLECTION(c)->name = name;
  add_ref(OBJ2_COLLECTION(c)->db);
  push_object(c);
}

void lookup_collection_program()
{
  push_text("Database.EJDB.Collection");
  SAFE_APPLY_MASTER("resolv", 1 );
  if(Pike_sp[-1].type != T_PROGRAM)
  {
    Pike_error("Unable to load class Database.EJDB.Collection.\n");
  }
  
  Collection_program = Pike_sp[-1].u.program;
  add_ref(Collection_program);
  pop_stack();
}


#undef internal_init_Database_defined
#define internal_init_Database_defined

#undef Database_event_handler_defined
#define Database_event_handler_defined
static void init_Database_struct(void)
#line 602 "ejdb.cmod"
{
}


#undef Database_gc_live_obj
#define Database_gc_live_obj

#undef internal_exit_Database_defined
#define internal_exit_Database_defined

#undef Database_event_handler_defined
#define Database_event_handler_defined
static void exit_Database_struct(void)
#line 606 "ejdb.cmod"
{
  EJDB * jb;
  jb = THIS->jb;
  if(jb && ejdbisopen(jb))
  { 
    printf("closing\n");
    ejdbclose(jb);
  }
  if(jb)
  {
    printf("freeing\n");
    ejdbdel(jb);
  }
  
  if(Collection_program)
    free_program(Collection_program);
}


#ifdef Database_event_handler_defined
static void Database_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_Database_defined
  case PROG_EVENT_INIT: init_Database_struct(); break;

#endif /* internal_init_Database_defined */

#ifdef internal_exit_Database_defined
  case PROG_EVENT_EXIT: exit_Database_struct(); break;

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

#endif /* Database_event_handler_defined */
/*! @endclass
 */

 
#undef extra_defined
#define extra_defined
#line 719 "ejdb.cmod"
PIKE_MODULE_INIT
 {
   
#ifdef class_LowCollection_defined

#ifdef PROG_LOWCOLLECTION_ID
#line 36 "ejdb.cmod"
  START_NEW_PROGRAM_ID(LOWCOLLECTION);
#else
#line 36 "ejdb.cmod"
  start_new_program();

#endif /* PROG_LOWCOLLECTION_ID */

#ifndef tObjImpl_LOWCOLLECTION

#undef tObjImpl_LOWCOLLECTION
#define tObjImpl_LOWCOLLECTION tObj

#endif /* tObjImpl_LOWCOLLECTION */

#ifdef THIS_LOWCOLLECTION
  LowCollection_storage_offset = ADD_STORAGE(struct LowCollection_struct);
#endif /* THIS_LOWCOLLECTION */

#ifdef var_db_LowCollection_defined
  PIKE_MAP_VARIABLE("db", LowCollection_storage_offset + OFFSETOF(LowCollection_struct, db),
                    tObj, PIKE_T_OBJECT, 0);
#endif /* var_db_LowCollection_defined */

#ifdef var_name_LowCollection_defined
  PIKE_MAP_VARIABLE("name", LowCollection_storage_offset + OFFSETOF(LowCollection_struct, name),
                    tStr, PIKE_T_STRING, 0);
#endif /* var_name_LowCollection_defined */

#ifdef LowCollection_event_handler_defined
  pike_set_prog_event_callback(LowCollection_event_handler);

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

#endif /* LowCollection_gc_live_obj */

#endif /* LowCollection_event_handler_defined */

#ifdef f_LowCollection_create_defined
  f_LowCollection_create_fun_num =
#line 47 "ejdb.cmod"
    ADD_FUNCTION2("create", f_LowCollection_create, tFunc(tNone,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_create_defined */

#ifdef f_LowCollection_cq__sprintf_defined
  f_LowCollection_cq__sprintf_fun_num =
#line 52 "ejdb.cmod"
    ADD_FUNCTION2("_sprintf", f_LowCollection_cq__sprintf, tFunc(tMix tMix,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_cq__sprintf_defined */

#ifdef f_LowCollection_delete_bson_defined
  f_LowCollection_delete_bson_fun_num =
#line 63 "ejdb.cmod"
    ADD_FUNCTION2("delete_bson", f_LowCollection_delete_bson, tFunc(tStr,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_delete_bson_defined */

#ifdef f_LowCollection_set_index_defined
  f_LowCollection_set_index_fun_num =
#line 102 "ejdb.cmod"
    ADD_FUNCTION2("set_index", f_LowCollection_set_index, tFunc(tStr "\10\200\0\0\0\177\377\377\377","\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_set_index_defined */

#ifdef f_LowCollection_load_bson_defined
  f_LowCollection_load_bson_fun_num =
#line 123 "ejdb.cmod"
    ADD_FUNCTION2("load_bson", f_LowCollection_load_bson, tFunc(tStr,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_load_bson_defined */

#ifdef f_LowCollection_save_bson_defined
  f_LowCollection_save_bson_fun_num =
#line 164 "ejdb.cmod"
    ADD_FUNCTION2("save_bson", f_LowCollection_save_bson, tFunc(tStr tOr(tStr,tVoid) tOr("\10\200\0\0\0\177\377\377\377",tVoid),tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_save_bson_defined */

#ifdef f_LowCollection_low_find_defined
  f_LowCollection_low_find_fun_num =
#line 219 "ejdb.cmod"
    ADD_FUNCTION2("low_find", f_LowCollection_low_find, tFunc(tStr tOr(tStr,tVoid) tOr("\10\200\0\0\0\177\377\377\377",tVoid),tArray), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_low_find_defined */

#ifdef f_LowCollection_begin_transaction_defined
  f_LowCollection_begin_transaction_fun_num =
#line 287 "ejdb.cmod"
    ADD_FUNCTION2("begin_transaction", f_LowCollection_begin_transaction, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_begin_transaction_defined */

#ifdef f_LowCollection_abort_transaction_defined
  f_LowCollection_abort_transaction_fun_num =
#line 305 "ejdb.cmod"
    ADD_FUNCTION2("abort_transaction", f_LowCollection_abort_transaction, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_abort_transaction_defined */

#ifdef f_LowCollection_commit_transaction_defined
  f_LowCollection_commit_transaction_fun_num =
#line 323 "ejdb.cmod"
    ADD_FUNCTION2("commit_transaction", f_LowCollection_commit_transaction, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_commit_transaction_defined */

#ifdef f_LowCollection_transaction_status_defined
  f_LowCollection_transaction_status_fun_num =
#line 341 "ejdb.cmod"
    ADD_FUNCTION2("transaction_status", f_LowCollection_transaction_status, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_transaction_status_defined */

#ifdef f_LowCollection_sync_defined
  f_LowCollection_sync_fun_num =
#line 363 "ejdb.cmod"
    ADD_FUNCTION2("sync", f_LowCollection_sync, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_sync_defined */
#line 36 "ejdb.cmod"
  LowCollection_program=end_program();
#line 36 "ejdb.cmod"
  LowCollection_program_fun_num=add_program_constant("LowCollection",LowCollection_program,ID_PROTECTED);

#endif /* class_LowCollection_defined */

#ifdef class_Database_defined

#ifdef PROG_DATABASE_ID
#line 388 "ejdb.cmod"
  START_NEW_PROGRAM_ID(DATABASE);
#else
#line 388 "ejdb.cmod"
  start_new_program();

#endif /* PROG_DATABASE_ID */

#ifndef tObjImpl_DATABASE

#undef tObjImpl_DATABASE
#define tObjImpl_DATABASE tObj

#endif /* tObjImpl_DATABASE */

#ifdef THIS_DATABASE
  Database_storage_offset = ADD_STORAGE(struct Database_struct);
#endif /* THIS_DATABASE */

#ifdef Database_event_handler_defined
  pike_set_prog_event_callback(Database_event_handler);

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

#endif /* Database_gc_live_obj */

#endif /* Database_event_handler_defined */

#ifdef f_Database_create_defined
  f_Database_create_fun_num =
#line 396 "ejdb.cmod"
    ADD_FUNCTION2("create", f_Database_create, tFunc(tStr "\10\200\0\0\0\177\377\377\377",tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_create_defined */

#ifdef f_Database_sync_defined
  f_Database_sync_fun_num =
#line 412 "ejdb.cmod"
    ADD_FUNCTION2("sync", f_Database_sync, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_sync_defined */

#ifdef f_Database_is_open_defined
  f_Database_is_open_fun_num =
#line 422 "ejdb.cmod"
    ADD_FUNCTION2("is_open", f_Database_is_open, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_is_open_defined */

#ifdef f_Database_close_defined
  f_Database_close_fun_num =
#line 429 "ejdb.cmod"
    ADD_FUNCTION2("close", f_Database_close, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_close_defined */

#ifdef f_Database_delete_collection_defined
  f_Database_delete_collection_fun_num =
#line 440 "ejdb.cmod"
    ADD_FUNCTION2("delete_collection", f_Database_delete_collection, tFunc(tStr "\10\200\0\0\0\177\377\377\377",tArray), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_delete_collection_defined */

#ifdef f_Database_get_collections_defined
  f_Database_get_collections_fun_num =
#line 455 "ejdb.cmod"
    ADD_FUNCTION2("get_collections", f_Database_get_collections, tFunc(tNone,tArray), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_get_collections_defined */

#ifdef f_Database_get_collection_defined
  f_Database_get_collection_fun_num =
#line 478 "ejdb.cmod"
    ADD_FUNCTION2("get_collection", f_Database_get_collection, tFunc(tStr,tObj), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_get_collection_defined */

#ifdef f_Database_create_collection_defined
  f_Database_create_collection_fun_num =
#line 509 "ejdb.cmod"
    ADD_FUNCTION2("create_collection", f_Database_create_collection, tFunc(tStr tOr(tMapping,tVoid),tObj), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_Database_create_collection_defined */
#line 388 "ejdb.cmod"
  Database_program=end_program();
#line 388 "ejdb.cmod"
  Database_program_fun_num=add_program_constant("Database",Database_program,0);

#endif /* class_Database_defined */

#ifdef extra_defined
#line 630 "ejdb.cmod"
{
   /* DB OBJECT CREATION CONSTANTS */

   /*! @decl constant JBOREADER
     *! Create: Open as a reader.
     */
   add_integer_constant("JBOREADER", JBOREADER, 0);

   /*! @decl constant JBOWRITER 
    *! Create: Open as a writer. 
   */
   add_integer_constant("JBOWRITER", JBOWRITER, 0);

   /*! @decl constant JBOCREAT 
    *! Create: Create if db file not exists.
    */
   add_integer_constant("JBOCREAT", JBOCREAT, 0);

   /*! @decl constant JBOTRUNC 
    *! Create: Truncate db on open.
    */
   add_integer_constant("JBOTRUNC", JBOTRUNC, 0);

   /*! @decl constant JBONOLCK 
    *! Create: Open without locking.
    */
   add_integer_constant("JBONOLCK", JBONOLCK, 0);

   /*! @decl constant JBOLCKNB
    *! Create: Lock without blocking.
    */
   add_integer_constant("JBOLCKNB", JBOLCKNB, 0);

   /*! @decl constant JBOTSYNC 
    *! Create: Synchronize every transaction. 
    */
   add_integer_constant("JBOTSYNC", JBOTSYNC, 0);


   /* INDEX CONSTANTS */

   /*! @decl constant JBIDXDROP 
    *! Index: Drop index. 
    */
   add_integer_constant("JBIDXDROP", JBIDXDROP, 0);

   /*! @decl constant JBIDXDROPALL 
    *! Index: Drop index for all types. 
    */
   add_integer_constant("JBIDXDROPALL", JBIDXDROPALL, 0);

   /*! @decl constant JBIDXOP 
    *! Index: Optimize index. 
    */
   add_integer_constant("JBIDXOP", JBIDXOP, 0);

   /*! @decl constant JBIDXREBLD 
    *! Index: Rebuild index. 
    */
   add_integer_constant("JBIDXREBLD", JBIDXREBLD, 0);

   /*! @decl constant JBIDXNUM 
    *! Index: Number index. 
    */
   add_integer_constant("JBIDXNUM", JBIDXNUM, 0);

   /*! @decl constant JBIDXSTR 
    *! Index: String index. 
    */
   add_integer_constant("JBIDXSTR", JBIDXSTR, 0);

   /*! @decl constant JBIDXARR 
    *! Index: Array token index. 
    */
   add_integer_constant("JBIDXARR", JBIDXARR, 0);

   /*! @decl constant JBIDXISTR 
    *! Index: Case insensitive string index. 
    */
   add_integer_constant("JBIDXISTR", JBIDXISTR, 0);


   /* QUERY CONSTANTS */

   /*! @decl constant JBQURYCOUNT
    *! Query only count(*) in find()
    */
   add_integer_constant("JBQRYCOUNT", JBQRYCOUNT, 0);
 }
 
#endif /* extra_defined */
;
 }

 PIKE_MODULE_EXIT
 {
   
#ifdef class_LowCollection_defined
  if(LowCollection_program) {
#line 36 "ejdb.cmod"
    free_program(LowCollection_program);
    LowCollection_program=0;
  }

#endif /* class_LowCollection_defined */

#ifdef class_Database_defined
  if(Database_program) {
#line 388 "ejdb.cmod"
    free_program(Database_program);
    Database_program=0;
  }

#endif /* class_Database_defined */
#line 726 "ejdb.cmod"
;
 }

 EJDB * getdb(struct object * db)
 {
    struct Database_struct * _db;
    _db = (OBJ2_DATABASE(db));
    return _db->jb; 
 }

 void throw_ejdb_error(struct object * db)
 {
   EJDB * _db;
   int ecode;
   
   _db = getdb(db);
   ecode = ejdbecode(_db);
/*printf("throwing error!\n"); */
   Pike_error(ejdberrmsg(ecode));
 }

 /*! @endmodule
  */

 /*! @endmodule
  */



gotpike.org | Copyright © 2004 - 2019 | Pike is a trademark of Department of Computer and Information Science, Linköping University