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.4/ejdb.c

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

#undef PRECOMPILE_API_VERSION
#define PRECOMPILE_API_VERSION 5



#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 array * or_queries;
#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 > 4) wrong_number_of_args_error("low_find",args,4);
#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_ARRAY) SIMPLE_ARG_TYPE_ERROR("low_find",2,"array|void");
#line 219 "ejdb.cmod"
debug_malloc_pass(or_queries=Pike_sp[1-args].u.array);
#line 219 "ejdb.cmod"
} else or_queries = NULL;
#line 219 "ejdb.cmod"
if (args > 2 &&    (TYPEOF(Pike_sp[2-args]) != PIKE_T_INT ||     Pike_sp[2-args].u.integer)) {
#line 219 "ejdb.cmod"
if(TYPEOF(Pike_sp[2-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("low_find",3,"string|void");
#line 219 "ejdb.cmod"
debug_malloc_pass(bson_hints=Pike_sp[2-args].u.string);
#line 219 "ejdb.cmod"
} else bson_hints = NULL;
#line 219 "ejdb.cmod"
if (args > 3) {
#line 219 "ejdb.cmod"
if(TYPEOF(Pike_sp[3-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("low_find",4,"int|void");
#line 219 "ejdb.cmod"
flags=Pike_sp+3-args; dmalloc_touch_svalue(Pike_sp+3-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;
    int numorq = 0;
    int q;
    EJDB * dbo;
    EJCOLL * coll;
    
    bson* orq = NULL;
    
    if(!THISLC->coll)
    {
      pop_n_elems(args);
      Pike_error("Collection not initialized properly.\n");
    }

    if(!THISLC->db)    
    {
      pop_n_elems(args);
      Pike_error("No db!\n");
    }

    if(!getdb(THISLC->db))
    {
      pop_n_elems(args);
      Pike_error("No low db.\n");
    }

    if(flags && flags->type == T_INT)
     {
       _flags = flags->u.integer;
     }
    
    bson_init_finished_data(&_bson, bson_query->str);
    
    if(or_queries)
    {
      struct svalue * sv;
      numorq = or_queries->size;
      orq = malloc(sizeof(bson) * numorq);
      for(q = 0; q < numorq; q++)
      {
        sv = ITEM(or_queries)+q;
        bson_init_finished_data(&(orq[q]), sv->u.string->str);
        
      }
    }
    
    if(bson_hints)
    {
      havehints = 1;
      bson_init_finished_data(&_hints, bson_hints->str);
      
    }    
    
   dbo = getdb(THISLC->db);
   coll = THISLC->coll;
   THREADS_ALLOW();

    if(havehints)
      q1 = ejdbcreatequery(dbo, &_bson, orq, numorq, &_hints);
   else
      q1 = ejdbcreatequery(dbo, &_bson, orq, numorq, NULL);

      res = ejdbqryexecute(coll, q1, &count, _flags, NULL);

   THREADS_DISALLOW();

   if (ejdbecode(dbo) == TCESUCCESS) {  
    pop_n_elems(args);

    if(_flags)
    {
      push_int(count);
    }
    else
    {
    /*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);
      }
      f_aggregate(count);

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

    /*Dispose query */
    ejdbquerydel(q1);

     }
    }
    else
    {
      /* failure */
      tclistdel(res);
      ejdbquerydel(q1);
      if(orq)
        free(orq);
      
      throw_ejdb_error(THISLC->db);
   }
   
 /*   bson_destroy(&_bson); */
     if(orq)
     { 
/*       for(q=0; q < numorq; q++) */
/*         bson_destroy(orq + q); */
     /*  free(orq); */
     }
  }
  
  }
/*! @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 347 "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 365 "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 383 "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 401 "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 423 "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 427 "ejdb.cmod"
}
     else do { INT_TYPE ret_=(0);  push_int(ret_); return; }while(0);
#line 429 "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 433 "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 437 "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_LowDatabase_defined
#define class_LowDatabase_defined
DEFAULT_CMOD_STORAGE struct program *LowDatabase_program=NULL;
static int LowDatabase_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
#line 454 "ejdb.cmod"
#define THISLD ((struct LowDatabase_struct *)get_storage(Pike_fp->current_object, LowDatabase_program))


#undef var_jb_LowDatabase_defined
#define var_jb_LowDatabase_defined

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

#undef THIS_LOWDATABASE
#define THIS_LOWDATABASE ((struct LowDatabase_struct *)(Pike_interpreter.frame_pointer->current_storage))

#undef OBJ2_LOWDATABASE
#define OBJ2_LOWDATABASE(o) ((struct LowDatabase_struct *)(o->storage+LowDatabase_storage_offset))

#undef GET_LOWDATABASE_STORAGE
#define GET_LOWDATABASE_STORAGE(o) ((struct LowDatabase_struct *)(o->storage+LowDatabase_storage_offset)
static ptrdiff_t LowDatabase_storage_offset;
struct LowDatabase_struct {

#ifdef var_jb_LowDatabase_defined
#line 456 "ejdb.cmod"
EJDB * jb;
#endif /* var_jb_LowDatabase_defined */
};
#ifdef PIKE_DEBUG
/* Ensure the struct is used in a variable declaration, or else gdb might not see it. */
static struct LowDatabase_struct *LowDatabase_gdb_dummy_ptr;
#endif
/*! @decl void create(string dbpath, int flags)
 */
#define f_LowDatabase_create_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_create_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_create(INT32 args) {
#line 460 "ejdb.cmod"
struct pike_string * dbpath;
#line 460 "ejdb.cmod"
INT_TYPE flags;
#line 460 "ejdb.cmod"
if(args != 2) wrong_number_of_args_error("create",args,2);
#line 460 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-2]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create",1,"string");
#line 460 "ejdb.cmod"
debug_malloc_pass(dbpath=Pike_sp[0-2].u.string);
#line 460 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-2]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("create",2,"int");
#line 460 "ejdb.cmod"
flags=Pike_sp[1-2].u.integer;
{
  static EJDB *jb;
  jb = ejdbnew();
  if (!ejdbopen(jb, dbpath->str, flags)) {
     int ecode;
     char msg2[256];
     const char * msg;
     ecode = ejdbecode(jb);
     msg = ejdberrmsg(ecode);
     snprintf(msg2, sizeof(msg2), "Error creating database object: %s\n", msg);
     Pike_error(msg2); 
  }
  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_LowDatabase_sync_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_sync_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_sync(INT32 args) {
#line 482 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("sync",args,0);
{
   if (!ejdbsyncdb(THISLD->jb)) {
       do { INT_TYPE ret_=(ejdbecode(THISLD->jb));  push_int(ret_); return; }while(0);
#line 486 "ejdb.cmod"
}
   else do { INT_TYPE ret_=(0);  push_int(ret_); return; }while(0);
#line 488 "ejdb.cmod"
}

}
/*! @decl int is_open()
 */
#define f_LowDatabase_is_open_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_is_open_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_is_open(INT32 args) {
#line 492 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("is_open",args,0);
{
   do { INT_TYPE ret_=((ejdbisopen(THISLD->jb)));  push_int(ret_); return; }while(0);
#line 495 "ejdb.cmod"
}

}
/*! @decl int close()
 */
#define f_LowDatabase_close_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_close_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_close(INT32 args) {
#line 499 "ejdb.cmod"
if(args != 0) wrong_number_of_args_error("close",args,0);
{
   if (!ejdbclose(THISLD->jb)) {
       do { INT_TYPE ret_=(ejdbecode(THISLD->jb));  push_int(ret_); return; }while(0);
#line 503 "ejdb.cmod"
}
   else do { INT_TYPE ret_=(0);  push_int(ret_); return; }while(0);
#line 505 "ejdb.cmod"
}

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

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

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

  colls = ejdbgetcolls(THISLD->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_LowDatabase_get_collection_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_get_collection_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_get_collection(INT32 args) {
#line 548 "ejdb.cmod"
struct pike_string * name;
#line 548 "ejdb.cmod"
if(args != 1) wrong_number_of_args_error("get_collection",args,1);
#line 548 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("get_collection",1,"string");
#line 548 "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(THISLD->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) 
  *!@param name
  *! name of the collection to create.
  *!@param opts
  *!large,
  *!compressed,
  *!records,
  *!cachedrecords
  */
#define f_LowDatabase_create_collection_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_create_collection_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_create_collection(INT32 args) {
#line 581 "ejdb.cmod"
struct pike_string * name;
#line 581 "ejdb.cmod"
struct mapping * opts;
#line 581 "ejdb.cmod"
if(args < 1) wrong_number_of_args_error("create_collection",args,1);
#line 581 "ejdb.cmod"
if(args > 2) wrong_number_of_args_error("create_collection",args,2);
#line 581 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create_collection",1,"string");
#line 581 "ejdb.cmod"
debug_malloc_pass(name=Pike_sp[0-args].u.string);
#line 581 "ejdb.cmod"
if (args > 1 &&    (TYPEOF(Pike_sp[1-args]) != PIKE_T_INT ||     Pike_sp[1-args].u.integer)) {
#line 581 "ejdb.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_MAPPING) SIMPLE_ARG_TYPE_ERROR("create_collection",2,"mapping(mixed:mixed)|void");
#line 581 "ejdb.cmod"
debug_malloc_pass(opts=Pike_sp[1-args].u.mapping);
#line 581 "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(THISLD->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;
  }
}


  }
/*! @decl string low_command(string bson)
   *!
   */
  #define f_LowDatabase_low_command_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_low_command_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_low_command(INT32 args) {
#line 641 "ejdb.cmod"
struct pike_string * bson_cmd;
#line 641 "ejdb.cmod"
if(args != 1) wrong_number_of_args_error("low_command",args,1);
#line 641 "ejdb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("low_command",1,"string");
#line 641 "ejdb.cmod"
debug_malloc_pass(bson_cmd=Pike_sp[0-1].u.string);
{
    bson _bson;

    bson *res; 
    EJDB * dbo;
    struct pike_string * bt;

#ifdef HAVE_EJDBCOMMAND

    if(!THISLD->jb)
    {
      pop_n_elems(args);
      Pike_error("No db!\n");
    }
    
    dbo = THISLD->jb;
    bson_init_finished_data(&_bson, bson_cmd->str);

    THREADS_ALLOW();

    res = ejdbcommand(dbo, &_bson);

    THREADS_DISALLOW();
    pop_stack();

    if(res)
    {
      bt = make_shared_binary_string(bson_data(res), bson_size(res));
      push_string(bt);
      bson_del(res);
    }
    else
    {
      push_int(0);
    }
#else
    pop_stack();
    Pike_error("low_command() is not available. please upgrade your ejdb library.\n");
#endif /* HAVE_EJDBCOMMAND */
  }  

}
#line 683 "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_LowDatabase_defined
#define internal_init_LowDatabase_defined

#undef LowDatabase_event_handler_defined
#define LowDatabase_event_handler_defined
static void init_LowDatabase_struct(void)
#line 720 "ejdb.cmod"
{
}


#undef LowDatabase_gc_live_obj
#define LowDatabase_gc_live_obj

#undef internal_exit_LowDatabase_defined
#define internal_exit_LowDatabase_defined

#undef LowDatabase_event_handler_defined
#define LowDatabase_event_handler_defined
static void exit_LowDatabase_struct(void)
#line 724 "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 LowDatabase_event_handler_defined
static void LowDatabase_event_handler(int ev) {
  switch(ev) {

#ifdef internal_init_LowDatabase_defined
  case PROG_EVENT_INIT: init_LowDatabase_struct(); break;

#endif /* internal_init_LowDatabase_defined */

#ifdef internal_exit_LowDatabase_defined
  case PROG_EVENT_EXIT: exit_LowDatabase_struct(); break;

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

#endif /* LowDatabase_event_handler_defined */
/*! @endclass
 */

 
#undef extra_defined
#define extra_defined
#line 862 "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(tArray,tVoid) 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 347 "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 365 "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 383 "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 401 "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 423 "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_LowDatabase_defined

#ifdef PROG_LOWDATABASE_ID
#line 448 "ejdb.cmod"
  START_NEW_PROGRAM_ID(LOWDATABASE);
#else
#line 448 "ejdb.cmod"
  start_new_program();

#endif /* PROG_LOWDATABASE_ID */

#ifndef tObjImpl_LOWDATABASE

#undef tObjImpl_LOWDATABASE
#define tObjImpl_LOWDATABASE tObj

#endif /* tObjImpl_LOWDATABASE */

#ifdef THIS_LOWDATABASE
  LowDatabase_storage_offset = ADD_STORAGE(struct LowDatabase_struct);
#endif /* THIS_LOWDATABASE */

#ifdef LowDatabase_event_handler_defined
  pike_set_prog_event_callback(LowDatabase_event_handler);

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

#endif /* LowDatabase_gc_live_obj */

#endif /* LowDatabase_event_handler_defined */

#ifdef f_LowDatabase_create_defined
  f_LowDatabase_create_fun_num =
#line 460 "ejdb.cmod"
    ADD_FUNCTION2("create", f_LowDatabase_create, tFunc(tStr "\10\200\0\0\0\177\377\377\377",tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_create_defined */

#ifdef f_LowDatabase_sync_defined
  f_LowDatabase_sync_fun_num =
#line 482 "ejdb.cmod"
    ADD_FUNCTION2("sync", f_LowDatabase_sync, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_sync_defined */

#ifdef f_LowDatabase_is_open_defined
  f_LowDatabase_is_open_fun_num =
#line 492 "ejdb.cmod"
    ADD_FUNCTION2("is_open", f_LowDatabase_is_open, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_is_open_defined */

#ifdef f_LowDatabase_close_defined
  f_LowDatabase_close_fun_num =
#line 499 "ejdb.cmod"
    ADD_FUNCTION2("close", f_LowDatabase_close, tFunc(tNone,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_close_defined */

#ifdef f_LowDatabase_delete_collection_defined
  f_LowDatabase_delete_collection_fun_num =
#line 510 "ejdb.cmod"
    ADD_FUNCTION2("delete_collection", f_LowDatabase_delete_collection, tFunc(tStr "\10\200\0\0\0\177\377\377\377",tArray), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_delete_collection_defined */

#ifdef f_LowDatabase_get_collections_defined
  f_LowDatabase_get_collections_fun_num =
#line 525 "ejdb.cmod"
    ADD_FUNCTION2("get_collections", f_LowDatabase_get_collections, tFunc(tNone,tArray), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_get_collections_defined */

#ifdef f_LowDatabase_get_collection_defined
  f_LowDatabase_get_collection_fun_num =
#line 548 "ejdb.cmod"
    ADD_FUNCTION2("get_collection", f_LowDatabase_get_collection, tFunc(tStr,tObj), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_get_collection_defined */

#ifdef f_LowDatabase_create_collection_defined
  f_LowDatabase_create_collection_fun_num =
#line 581 "ejdb.cmod"
    ADD_FUNCTION2("create_collection", f_LowDatabase_create_collection, tFunc(tStr tOr(tMapping,tVoid),tObj), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_create_collection_defined */

#ifdef f_LowDatabase_low_command_defined
  f_LowDatabase_low_command_fun_num =
#line 641 "ejdb.cmod"
    ADD_FUNCTION2("low_command", f_LowDatabase_low_command, tFunc(tStr,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_low_command_defined */
#line 448 "ejdb.cmod"
  LowDatabase_program=end_program();
#line 448 "ejdb.cmod"
  LowDatabase_program_fun_num=add_program_constant("LowDatabase",LowDatabase_program,0);

#endif /* class_LowDatabase_defined */

#ifdef extra_defined
#line 748 "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);

  /* COMMAND CONSTANTS */
#ifdef HAVE_EJDBCOMMAND

   /*! @decl constant JBJSONEXPORT
    *!
    *! Export data as JSON files instead exporting into BSONs.
    */
  add_integer_constant("JBJSONEXPORT", JBJSONEXPORT, 0);

   /*! @decl constant JBIMPORTUPDATE
    *!
    *! Update existing collection entries with imported ones.
    *! Existing collections will not be recreated.
    *! For existing collections options will not be imported.
    */
  add_integer_constant("JBIMPORTUPDATE", JBIMPORTUPDATE, 0);

   /*! @decl constant JBIMPORTREPLACE
    *! Recreate existing collections and replace all their data
    *! with imported entries. Collections options will be imported.
    *!
    */
  add_integer_constant("JBIMPORTREPLACE", JBIMPORTREPLACE, 0);
#endif /* HAVE_EJDB_COMMAND */
 }
 
#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_LowDatabase_defined
  if(LowDatabase_program) {
#line 448 "ejdb.cmod"
    free_program(LowDatabase_program);
    LowDatabase_program=0;
  }

#endif /* class_LowDatabase_defined */
#line 869 "ejdb.cmod"
;
 }

 EJDB * getdb(struct object * dbo)
 {
    EJDB * db;
    struct LowDatabase_struct * _db;
    _db = (OBJ2_LOWDATABASE(dbo));
    db = _db->jb;
    return db; 
 }

 void throw_ejdb_error(struct object * db)
 {
   EJDB * _db;
   int ecode;
   char msg2[256];
   const char * msg;
   
   _db = getdb(db);
   ecode = ejdbecode(_db);
   msg = ejdberrmsg(ecode);
   snprintf(msg2, sizeof(msg2), "Error creating database object: %s\n", msg);
   Pike_error(msg2);
 }

 /*! @endmodule
  */

 /*! @endmodule
  */



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