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.MongoDB
Viewing contents of Database_MongoDB-1.1/mongodb.c

/* Generated from "mongodb.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 MongoDB
 */

#line 7 "mongodb.cmod"
#define _GNU_SOURCE

#include "mongodb_config.h"
#include "util.h"

/*#if HAVE_MONGO_H
*/
#include 
/*#endif*/ /* HAVE_MONGO_H */

extern struct program * MonogDB_program;
struct program * Collection_program;

mongo * getdb(struct object * db);
void push_coll(struct pike_string * coll);
void lookup_collection_program();
void throw_mongodb_error(int ret, 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_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_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 36 "mongodb.cmod"
#define COLL_DB(X) (mongo *)(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 THISLD ((struct LowDatabase_struct *)get_storage(Pike_fp->current_object, LowDatabase_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 40 "mongodb.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 45 "mongodb.cmod"
struct svalue * format;
#line 45 "mongodb.cmod"
struct svalue * bar;
#line 45 "mongodb.cmod"
if(args != 2) wrong_number_of_args_error("_sprintf",args,2);
#line 45 "mongodb.cmod"
format=Pike_sp+0-2; dmalloc_touch_svalue(Pike_sp+0-2);
#line 45 "mongodb.cmod"
bar=Pike_sp+1-2; dmalloc_touch_svalue(Pike_sp+1-2);
{
    push_text("MongoDB.Collection(");
    push_string(THISLC->name);
    f_add(2);
    push_text(")");
    f_add(2);
  }
  
  }
#define f_LowCollection_update_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_update_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_update_bson(INT32 args) {
#line 54 "mongodb.cmod"
struct pike_string * bson_cond;
#line 54 "mongodb.cmod"
struct pike_string * bson_op;
#line 54 "mongodb.cmod"
INT_TYPE flags;
#line 54 "mongodb.cmod"
if(args != 3) wrong_number_of_args_error("update_bson",args,3);
#line 54 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-3]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("update_bson",1,"string");
#line 54 "mongodb.cmod"
debug_malloc_pass(bson_cond=Pike_sp[0-3].u.string);
#line 54 "mongodb.cmod"
if(TYPEOF(Pike_sp[1-3]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("update_bson",2,"string");
#line 54 "mongodb.cmod"
debug_malloc_pass(bson_op=Pike_sp[1-3].u.string);
#line 54 "mongodb.cmod"
if(TYPEOF(Pike_sp[2-3]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("update_bson",3,"int");
#line 54 "mongodb.cmod"
flags=Pike_sp[2-3].u.integer;
{
    bson _bson_cond;
    bson _bson_op;
    int ret = 0;
    char * ns;
    mongo * db;
    int ret2;
    
    ns = THIS->name->str; /* TODO convert to UTF8. */
    
    db = getdb(THISLC->db);
    bson_init_finished_data(&_bson_cond, bson_cond->str);
    bson_init_finished_data(&_bson_op, bson_op->str);
    
    ret = mongo_update(db, ns, &_bson_cond, &_bson_op, flags, NULL);
    
    ret2 = ret;

    if(ret == MONGO_ERROR && db->err == MONGO_IO_ERROR)
    {
      if(mongo_reconnect(db) != MONGO_ERROR)
      {
        ret = mongo_update(db, ns, &_bson_cond, &_bson_op, flags, NULL);
      }
    }

    if(ret != MONGO_OK)
    {
    /*      pop_n_elems(args); */
      throw_mongodb_error(ret, THISLC->db);
    }

    /*    bson_print_raw(bson_data(&_bson), 10); */
    do { INT_TYPE ret_=(ret); pop_n_elems(3); push_int(ret_); return; }while(0);
#line 89 "mongodb.cmod"
}
  
  }
#define f_LowCollection_insert_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_insert_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_insert_bson(INT32 args) {
#line 91 "mongodb.cmod"
struct pike_string * bson_doc;
#line 91 "mongodb.cmod"
if(args != 1) wrong_number_of_args_error("insert_bson",args,1);
#line 91 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("insert_bson",1,"string");
#line 91 "mongodb.cmod"
debug_malloc_pass(bson_doc=Pike_sp[0-1].u.string);
{
    bson _bson;
    int ret = 0;
    char * ns;
    mongo * db;
    int ret2;
    
    ns = THIS->name->str; /* TODO convert to UTF8. */
    
    db = getdb(THISLC->db);
    bson_init_finished_data(&_bson, bson_doc->str);

/*    bson_print_raw(bson_data(&_bson), 10); */
    ret = mongo_insert(db, ns, &_bson, NULL);


  ret2 = ret;
  
    if(ret == MONGO_ERROR && db->err == MONGO_IO_ERROR)
    {
      if(mongo_reconnect(db) != MONGO_ERROR)
      {
        ret = mongo_insert(db, ns, &_bson, NULL);
      }
    }
    
    if(ret != MONGO_OK)
    {
/*      pop_stack(); */
      throw_mongodb_error(ret, THISLC->db);
    }
  
/*    bson_print_raw(bson_data(&_bson), 10); */
          
    do { INT_TYPE ret_=(ret); pop_stack(); push_int(ret_); return; }while(0);
#line 127 "mongodb.cmod"
}
  
    }
#define f_LowCollection_remove_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_remove_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_remove_bson(INT32 args) {
#line 129 "mongodb.cmod"
struct pike_string * bson_doc;
#line 129 "mongodb.cmod"
if(args != 1) wrong_number_of_args_error("remove_bson",args,1);
#line 129 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("remove_bson",1,"string");
#line 129 "mongodb.cmod"
debug_malloc_pass(bson_doc=Pike_sp[0-1].u.string);
{
      bson _bson;
      int ret = 0;
      char * ns;
      mongo * db;
      int ret2;

      ns = THIS->name->str; /* TODO convert to UTF8. */

      db = getdb(THISLC->db);
      bson_init_finished_data(&_bson, bson_doc->str);

      ret = mongo_remove(db, ns, &_bson, NULL);
      ret2 = ret;

      if(ret2 == MONGO_ERROR && db->err == MONGO_IO_ERROR)
      {
        if(mongo_reconnect(db) != MONGO_ERROR)
        {
          ret = mongo_remove(db, ns, &_bson, NULL);
        }
      }

      if(ret != MONGO_OK)
      {
        throw_mongodb_error(ret, THISLC->db);
      }

      do { INT_TYPE ret_=(ret); pop_stack(); push_int(ret_); return; }while(0);
#line 159 "mongodb.cmod"
}
    
   }
#define f_LowCollection_create_index_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowCollection_create_index_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowCollection_create_index_bson(INT32 args) {
#line 161 "mongodb.cmod"
struct pike_string * bson_doc;
#line 161 "mongodb.cmod"
INT_TYPE flags;
#line 161 "mongodb.cmod"
if(args != 2) wrong_number_of_args_error("create_index_bson",args,2);
#line 161 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-2]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create_index_bson",1,"string");
#line 161 "mongodb.cmod"
debug_malloc_pass(bson_doc=Pike_sp[0-2].u.string);
#line 161 "mongodb.cmod"
if(TYPEOF(Pike_sp[1-2]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("create_index_bson",2,"int");
#line 161 "mongodb.cmod"
flags=Pike_sp[1-2].u.integer;
{
      bson _bson;
      int ret = 0;
      char * ns;
      mongo * db;
      int ret2;

      ns = THIS->name->str; /* TODO convert to UTF8. */

      db = getdb(THISLC->db);
      bson_init_finished_data(&_bson, bson_doc->str);

  /*    bson_print_raw(bson_data(&_bson), 10); */
      ret = mongo_create_index(db, ns, &_bson, flags, NULL);


    ret2 = ret;

      if(ret == MONGO_ERROR && db->err == MONGO_IO_ERROR)
      {
        if(mongo_reconnect(db) != MONGO_ERROR)
        {
          ret = mongo_insert(db, ns, &_bson, NULL);
        }
      }

      if(ret != MONGO_OK)
      {
  /*      pop_stack(); */
        throw_mongodb_error(ret, THISLC->db);
      }

  /*    bson_print_raw(bson_data(&_bson), 10); */

      do { INT_TYPE ret_=(ret); pop_n_elems(2); push_int(ret_); return; }while(0);
#line 197 "mongodb.cmod"
}
        
    }
#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 199 "mongodb.cmod"
struct pike_string * query_bson;
#line 199 "mongodb.cmod"
if(args != 1) wrong_number_of_args_error("low_find",args,1);
#line 199 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("low_find",1,"string");
#line 199 "mongodb.cmod"
debug_malloc_pass(query_bson=Pike_sp[0-1].u.string);
{
    int ret;
    char * ns;
    mongo * db;
    bson query;
    mongo_cursor cursor[1];
    int count = 0;
    
    ns = THIS->name->str; /* TODO convert to UTF8. */

    db = getdb(THISLC->db);
    bson_init_finished_data(&query, query_bson->str);
    mongo_cursor_init( cursor, db, ns );
    mongo_cursor_set_query( cursor, &query );
    pop_n_elems(args);
    while( mongo_cursor_next( cursor ) == MONGO_OK ) {
      struct pike_string * bt;
      const bson * _rb;
      
      _rb = mongo_cursor_bson(cursor);
      
      bt = make_shared_binary_string(bson_data(_rb), bson_size(_rb));                 
      push_string(bt);
      count++;
    }
    f_aggregate(count);

/*    bson_destroy( query ); */
    mongo_cursor_destroy( cursor );

    }

  }

#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 233 "mongodb.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 237 "mongodb.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

#undef var_db_LowDatabase_defined
#define var_db_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_db_LowDatabase_defined
#line 253 "mongodb.cmod"
mongo * db;
#endif /* var_db_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|void replica_set)
 */

#define f_LowDatabase_create_1_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_create_1_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_create_1(INT32 args) {
#line 258 "mongodb.cmod"
if(args != 0) wrong_number_of_args_error("create",args,0);
{
  mongo * db;
  int status;

  db = malloc(sizeof(mongo));
  mongo_init(db);
  
  THIS->db = db;
}

}
#define f_LowDatabase_create_2_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_create_2_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_create_2(INT32 args) {
#line 269 "mongodb.cmod"
struct pike_string * replica_set;
#line 269 "mongodb.cmod"
if(args != 1) wrong_number_of_args_error("create",args,1);
#line 269 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("create",1,"string");
#line 269 "mongodb.cmod"
debug_malloc_pass(replica_set=Pike_sp[0-1].u.string);
{
  mongo * db;
  int status;

  db = malloc(sizeof(mongo));
  mongo_replica_set_init(db, replica_set->str);
  
  THIS->db = db;
}

}

#if defined(f_LowDatabase_create_1_defined) || defined(f_LowDatabase_create_2_defined)
#define f_LowDatabase_create_defined
DEFAULT_CMOD_STORAGE ptrdiff_t LowDatabase_f_LowDatabase_create_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_create(INT32 args) {
  switch(args) {
   case 0:

#ifdef f_LowDatabase_create_1_defined
    f_LowDatabase_create_1(args);
    return;

#endif /* f_LowDatabase_create_1_defined */
    break;
   case 1:

#ifdef f_LowDatabase_create_2_defined
    f_LowDatabase_create_2(args);
    return;

#endif /* f_LowDatabase_create_2_defined */
    break;
   default:
    wrong_number_of_args_error("create",args,0);
  }
}

#endif /* f_LowDatabase_create_1_defined, f_LowDatabase_create_2_defined */
/*! @decl void add_seed(string ip, int|void port)
 *!
 *! add a seed to the replica set connection configuration.
 *!
 */
#define f_LowDatabase_add_seed_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_add_seed_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_add_seed(INT32 args) {
#line 285 "mongodb.cmod"
struct pike_string * ip;
#line 285 "mongodb.cmod"
struct svalue * port;
#line 285 "mongodb.cmod"
if(args < 1) wrong_number_of_args_error("add_seed",args,1);
#line 285 "mongodb.cmod"
if(args > 2) wrong_number_of_args_error("add_seed",args,2);
#line 285 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("add_seed",1,"string");
#line 285 "mongodb.cmod"
debug_malloc_pass(ip=Pike_sp[0-args].u.string);
#line 285 "mongodb.cmod"
if (args > 1) {
#line 285 "mongodb.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("add_seed",2,"int|void");
#line 285 "mongodb.cmod"
port=Pike_sp+1-args; dmalloc_touch_svalue(Pike_sp+1-args);
#line 285 "mongodb.cmod"
} else port = NULL;
{
  int prt;
  
  if(THIS->db && (THIS->db->connected))
    Pike_error("Database already connected.\n");
  if(THIS->db && !THIS->db->replica_set)
    Pike_error("Cannot add seed without using replica set name.\n");

  if(port)
    prt = port->u.integer;
  else
    prt = MONGO_DEFAULT_PORT;

  mongo_replica_set_add_seed(THIS->db, ip->str, prt);
  pop_n_elems(args);
}

}
/*! @decl void connect(string ip, int|void port)
 */
 #define f_LowDatabase_connect_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_connect_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_connect(INT32 args) {
#line 305 "mongodb.cmod"
struct pike_string * ip;
#line 305 "mongodb.cmod"
struct svalue * port;
#line 305 "mongodb.cmod"
if(args < 1) wrong_number_of_args_error("connect",args,1);
#line 305 "mongodb.cmod"
if(args > 2) wrong_number_of_args_error("connect",args,2);
#line 305 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-args]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("connect",1,"string");
#line 305 "mongodb.cmod"
debug_malloc_pass(ip=Pike_sp[0-args].u.string);
#line 305 "mongodb.cmod"
if (args > 1) {
#line 305 "mongodb.cmod"
if(TYPEOF(Pike_sp[1-args]) != PIKE_T_INT) SIMPLE_ARG_TYPE_ERROR("connect",2,"int|void");
#line 305 "mongodb.cmod"
port=Pike_sp+1-args; dmalloc_touch_svalue(Pike_sp+1-args);
#line 305 "mongodb.cmod"
} else port = NULL;
{
   int status;
   int prt;
   
   if(THIS->db && THIS->db->replica_set)
     Pike_error("Cannot connect directly when using a replica set.\n");

   if(THIS->db && (THIS->db->connected))
     Pike_error("Database already connected.\n");


   if(port)
     prt = port->u.integer;
   else
     prt = MONGO_DEFAULT_PORT;

   mongo_set_op_timeout(THIS->db, 2000);
   status = mongo_client(THIS->db, ip->str, prt);
   if( status != MONGO_OK ) 
   {
     pop_n_elems(args);
     switch(THIS->db->err)
     {
       case MONGO_CONN_NO_SOCKET:  Pike_error( "no socket\n" );
       case MONGO_CONN_FAIL:       Pike_error( "connection failed\n" );
       case MONGO_CONN_NOT_MASTER: Pike_error( "not master\n" );
       default: Pike_error("unknown error.\n");
     }
   }

   pop_n_elems(args);
 }

}
/*! @decl void connect_replica_set()
 *!
 *! connect to a replica set, having specified the seeds using @[add_seed()].
 */
#define f_LowDatabase_connect_replica_set_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_connect_replica_set_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_connect_replica_set(INT32 args) {
#line 343 "mongodb.cmod"
if(args != 0) wrong_number_of_args_error("connect_replica_set",args,0);
{
  int status;
  
  if(THIS->db && (THIS->db->connected))
    Pike_error("Database already connected.\n");
  
  if(THIS->db && !THIS->db->replica_set)
    Pike_error("Cannot connect without specifying a replica set.\n");
  
  status = mongo_replica_set_client(THIS->db);
  
  if( status != MONGO_OK ) 
   {
     pop_n_elems(args);
     switch(THIS->db->err)
     {
       case MONGO_CONN_NO_SOCKET:  Pike_error( "no socket\n" );
       case MONGO_CONN_FAIL:       Pike_error( "connection failed\n" );
       case MONGO_CONN_NOT_MASTER: Pike_error( "not master\n" );
       default: Pike_error("unknown error.\n");
     }
   }

   pop_n_elems(args);
}

}
/*! @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 373 "mongodb.cmod"
struct pike_string * name;
#line 373 "mongodb.cmod"
if(args != 1) wrong_number_of_args_error("get_collection",args,1);
#line 373 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-1]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("get_collection",1,"string");
#line 373 "mongodb.cmod"
debug_malloc_pass(name=Pike_sp[0-1].u.string);
{  
  if(!THIS->db || !(THIS->db->connected))
    Pike_error("Database not connected yet.\n");
    
  add_ref(name);
  pop_n_elems(args);
  push_coll(name);
  free_string(name);
  return;
}

}
/*! @decl int authenticate(string db, string username, string password)
 *!
 */
#define f_LowDatabase_authenticate_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_authenticate_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_authenticate(INT32 args) {
#line 388 "mongodb.cmod"
struct pike_string * db;
#line 388 "mongodb.cmod"
struct pike_string * username;
#line 388 "mongodb.cmod"
struct pike_string * password;
#line 388 "mongodb.cmod"
if(args != 3) wrong_number_of_args_error("authenticate",args,3);
#line 388 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-3]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("authenticate",1,"string");
#line 388 "mongodb.cmod"
debug_malloc_pass(db=Pike_sp[0-3].u.string);
#line 388 "mongodb.cmod"
if(TYPEOF(Pike_sp[1-3]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("authenticate",2,"string");
#line 388 "mongodb.cmod"
debug_malloc_pass(username=Pike_sp[1-3].u.string);
#line 388 "mongodb.cmod"
if(TYPEOF(Pike_sp[2-3]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("authenticate",3,"string");
#line 388 "mongodb.cmod"
debug_malloc_pass(password=Pike_sp[2-3].u.string);
{
  int ret;

  if(!THIS->db || !(THIS->db->connected))
    Pike_error("Database not connected yet.\n");

  ret = mongo_cmd_authenticate(THIS->db, db->str, username->str, password->str);
  pop_n_elems(args);
  push_int(ret);
}
  
  }
#define f_LowDatabase_run_command_bson_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_run_command_bson_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_run_command_bson(INT32 args) {
#line 400 "mongodb.cmod"
struct pike_string * dbname;
#line 400 "mongodb.cmod"
struct pike_string * cmdbson;
#line 400 "mongodb.cmod"
if(args != 2) wrong_number_of_args_error("run_command_bson",args,2);
#line 400 "mongodb.cmod"
if(TYPEOF(Pike_sp[0-2]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("run_command_bson",1,"string");
#line 400 "mongodb.cmod"
debug_malloc_pass(dbname=Pike_sp[0-2].u.string);
#line 400 "mongodb.cmod"
if(TYPEOF(Pike_sp[1-2]) != PIKE_T_STRING) SIMPLE_ARG_TYPE_ERROR("run_command_bson",2,"string");
#line 400 "mongodb.cmod"
debug_malloc_pass(cmdbson=Pike_sp[1-2].u.string);
{
    bson _bson;
    int ret = 0;
    mongo * db;
    char * ns;
    bson out;
    struct pike_string * bt;
    
    db = THISLD->db;
    ns = dbname->str; /* TODO convert to UTF8. */

    if(!THIS->db || !(THIS->db->connected))
      Pike_error("Database not connected yet.\n");
    
    bson_init_finished_data(&_bson, cmdbson->str);
    
    ret = mongo_run_command( db, ns, &_bson, &out );
    if(ret == MONGO_ERROR && db->err == MONGO_IO_ERROR)
      {
        if(mongo_reconnect(db) != MONGO_ERROR)
        {
          ret = mongo_run_command(db, ns, &_bson, &out);
        }
      }

    if(ret != MONGO_OK)
    {
 /*    printf("retval: %d\n", ret); */
 /* printf("res: %s\n", bson_data(&out)); */
 /*   printf("err: %d, %d, %s, %d, %s\n", db->err, db->errcode, db->errstr, db->lasterrcode, db->lasterrstr); */
        throw_mongodb_error(ret, Pike_fp->current_object);
    }

      bt = make_shared_binary_string(bson_data(&out), bson_size(&out));                 

      pop_n_elems(args);
      
      push_string(bt);
  }

}
/*! @decl string get_replica_set_name()
 *!
 */
#define f_LowDatabase_get_replica_set_name_defined
DEFAULT_CMOD_STORAGE ptrdiff_t f_LowDatabase_get_replica_set_name_fun_num = 0;
DEFAULT_CMOD_STORAGE void f_LowDatabase_get_replica_set_name(INT32 args) {
#line 444 "mongodb.cmod"
if(args != 0) wrong_number_of_args_error("get_replica_set_name",args,0);
{
  if(!THIS->db || !THIS->db->replica_set)
    Pike_error("no replica set specified.\n");

  push_text(THIS->db->replica_set->name);
}

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

void push_coll(struct pike_string * coll)
{
  struct object * c;
  if(!Collection_program)
    lookup_collection_program();
  c = clone_object(Collection_program, 0);
  add_ref(coll);
  OBJ2_COLLECTION(c)->db = this_object();
  OBJ2_COLLECTION(c)->name = coll;
  add_ref(OBJ2_COLLECTION(c)->db);
  push_object(c);
}

void lookup_collection_program()
{
  push_text("Database.MongoDB.Collection");
  SAFE_APPLY_MASTER("resolv", 1 );
  if(Pike_sp[-1].type != T_PROGRAM)
  {
    Pike_error("Unable to load class Database.MongoDB.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 482 "mongodb.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 486 "mongodb.cmod"
{
  mongo * db;
  db = THIS->db;
  if(db)
  { 
    mongo_destroy(db);
  }
  
  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 544 "mongodb.cmod"
PIKE_MODULE_INIT
 {
   
#ifdef class_LowCollection_defined

#ifdef PROG_LOWCOLLECTION_ID
#line 29 "mongodb.cmod"
  START_NEW_PROGRAM_ID(LOWCOLLECTION);
#else
#line 29 "mongodb.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 40 "mongodb.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 45 "mongodb.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_update_bson_defined
  f_LowCollection_update_bson_fun_num =
#line 54 "mongodb.cmod"
    ADD_FUNCTION2("update_bson", f_LowCollection_update_bson, tFunc(tStr 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_update_bson_defined */

#ifdef f_LowCollection_insert_bson_defined
  f_LowCollection_insert_bson_fun_num =
#line 91 "mongodb.cmod"
    ADD_FUNCTION2("insert_bson", f_LowCollection_insert_bson, tFunc(tStr,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_insert_bson_defined */

#ifdef f_LowCollection_remove_bson_defined
  f_LowCollection_remove_bson_fun_num =
#line 129 "mongodb.cmod"
    ADD_FUNCTION2("remove_bson", f_LowCollection_remove_bson, tFunc(tStr,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_remove_bson_defined */

#ifdef f_LowCollection_create_index_bson_defined
  f_LowCollection_create_index_bson_fun_num =
#line 161 "mongodb.cmod"
    ADD_FUNCTION2("create_index_bson", f_LowCollection_create_index_bson, 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_create_index_bson_defined */

#ifdef f_LowCollection_low_find_defined
  f_LowCollection_low_find_fun_num =
#line 199 "mongodb.cmod"
    ADD_FUNCTION2("low_find", f_LowCollection_low_find, tFunc(tStr,tArray), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowCollection_low_find_defined */
#line 29 "mongodb.cmod"
  LowCollection_program=end_program();
#line 29 "mongodb.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 248 "mongodb.cmod"
  START_NEW_PROGRAM_ID(LOWDATABASE);
#else
#line 248 "mongodb.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
  LowDatabase_f_LowDatabase_create_fun_num =
#line 269 "mongodb.cmod"
    ADD_FUNCTION2("create", f_LowDatabase_create, tOr(tFunc(tNone,tVoid),tFunc(tStr,tVoid)), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_create_defined */

#ifdef f_LowDatabase_add_seed_defined
  f_LowDatabase_add_seed_fun_num =
#line 285 "mongodb.cmod"
    ADD_FUNCTION2("add_seed", f_LowDatabase_add_seed, tFunc(tStr tOr("\10\200\0\0\0\177\377\377\377",tVoid),tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_add_seed_defined */

#ifdef f_LowDatabase_connect_defined
  f_LowDatabase_connect_fun_num =
#line 305 "mongodb.cmod"
    ADD_FUNCTION2("connect", f_LowDatabase_connect, tFunc(tStr tOr("\10\200\0\0\0\177\377\377\377",tVoid),tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_connect_defined */

#ifdef f_LowDatabase_connect_replica_set_defined
  f_LowDatabase_connect_replica_set_fun_num =
#line 343 "mongodb.cmod"
    ADD_FUNCTION2("connect_replica_set", f_LowDatabase_connect_replica_set, tFunc(tNone,tVoid), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_connect_replica_set_defined */

#ifdef f_LowDatabase_get_collection_defined
  f_LowDatabase_get_collection_fun_num =
#line 373 "mongodb.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_authenticate_defined
  f_LowDatabase_authenticate_fun_num =
#line 388 "mongodb.cmod"
    ADD_FUNCTION2("authenticate", f_LowDatabase_authenticate, tFunc(tStr tStr tStr,"\10\200\0\0\0\177\377\377\377"), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_authenticate_defined */

#ifdef f_LowDatabase_run_command_bson_defined
  f_LowDatabase_run_command_bson_fun_num =
#line 400 "mongodb.cmod"
    ADD_FUNCTION2("run_command_bson", f_LowDatabase_run_command_bson, tFunc(tStr tStr,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_run_command_bson_defined */

#ifdef f_LowDatabase_get_replica_set_name_defined
  f_LowDatabase_get_replica_set_name_fun_num =
#line 444 "mongodb.cmod"
    ADD_FUNCTION2("get_replica_set_name", f_LowDatabase_get_replica_set_name, tFunc(tNone,tStr), 0, OPT_EXTERNAL_DEPEND|OPT_SIDE_EFFECT);

#endif /* f_LowDatabase_get_replica_set_name_defined */
#line 248 "mongodb.cmod"
  LowDatabase_program=end_program();
#line 248 "mongodb.cmod"
  LowDatabase_program_fun_num=add_program_constant("LowDatabase",LowDatabase_program,ID_PROTECTED);

#endif /* class_LowDatabase_defined */

#ifdef extra_defined
#line 504 "mongodb.cmod"
{
 
 /*! @decl constant UPDATE_UPSERT 
  *! Index: Update/Insert operation. 
  */
 add_integer_constant("UPDATE_UPSERT", MONGO_UPDATE_UPSERT, 0);
 
 /*! @decl constant UPDATE_MULTI 
   *! Index: Multi-object Update operation. 
   */
  add_integer_constant("UPDATE_MULTI", MONGO_UPDATE_MULTI, 0);
 
 /*! @decl constant UPDATE_MULTI 
   *! Index: Multi-object Update operation. 
   */
  add_integer_constant("UPDATE_BASIC", MONGO_UPDATE_BASIC, 0);
 
 
  /* INDEX Constants */
 
  /*! @decl constant INDEX_UNIQUE 
     *! Index: Multi-object Update operation. 
     */
    add_integer_constant("INDEX_UNIQUE", MONGO_INDEX_UNIQUE, 0);
 
    /*! @decl constant INDEX_DROP_DUPS 
       *! Index: Multi-object Update operation. 
       */
      add_integer_constant("INDEX_DROP_DUPS", MONGO_INDEX_DROP_DUPS, 0);
 
      /*! @decl constant INDEX_BACKGROUND 
         *! Index: Multi-object Update operation. 
         */
        add_integer_constant("INDEX_BACKGROUND", MONGO_INDEX_BACKGROUND, 0);
 
        /*! @decl constant INDEX_SPARSE 
           *! Index: Multi-object Update operation. 
           */
          add_integer_constant("INDEX_SPARSE", MONGO_INDEX_SPARSE, 0);  
 }
 
#endif /* extra_defined */
;
 }

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

#endif /* class_LowCollection_defined */

#ifdef class_LowDatabase_defined
  if(LowDatabase_program) {
#line 248 "mongodb.cmod"
    free_program(LowDatabase_program);
    LowDatabase_program=0;
  }

#endif /* class_LowDatabase_defined */
#line 551 "mongodb.cmod"
;
 }

 void throw_mongodb_error(int ret, struct object * db)
 {
   mongo * _db;
   int ecode;
   char msg2[256];
   const char * msg;

   _db = getdb(db);
   
/*   printf("ret: %d\n", ret); */
   switch(_db->err)
   {
     case MONGO_CONN_NO_SOCKET:    /**< Could not create a socket. */
       Pike_error("Could not create a socket.\n");
     case MONGO_CONN_FAIL:         /**< An error occured while calling connect(). */
       Pike_error("An error occured while calling connect().\n");
     case MONGO_CONN_ADDR_FAIL:    /**< An error occured while calling getaddrinfo(). */
       Pike_error("An error occured while calling getaddrinfo().\n");
     case MONGO_CONN_NOT_MASTER:   /**< Warning: connected to a non-master node (read-only). */
       Pike_error("Warning: connected to a non-master node (read-only).\n");
     case MONGO_CONN_BAD_SET_NAME: /**< Given rs name doesn't match this replica set. */
       Pike_error("Given rs name doesn't match this replica set.\n");
     case MONGO_CONN_NO_PRIMARY:   /**< Can't find primary in replica set. Connection closed. */
       Pike_error("Can't find primary in replica set. Connection closed.\n");

     case MONGO_IO_ERROR:          /**< An error occurred while reading or writing on the socket. */
       Pike_error("An error occurred while reading or writing on the socket.\n");
     case MONGO_SOCKET_ERROR:      /**< Other socket error. */
       Pike_error("Other socket error.\n");
     case MONGO_READ_SIZE_ERROR:   /**< The response is not the expected length. */
       Pike_error("The response is not the expected length.\n");
     case MONGO_COMMAND_FAILED:    /**< The command returned with 'ok' value of 0. */
       Pike_error("The command returned with 'ok' value of 0.\n");
     case MONGO_WRITE_ERROR:       /**< Write with given write_concern returned an error. */
       Pike_error("Write with given write_concern returned an error.\n");
     case MONGO_NS_INVALID:        /**< The name for the ns (database or collection) is invalid. */
       Pike_error("The name for the ns (database or collection) is invalid.\n");
     case MONGO_BSON_INVALID:      /**< BSON not valid for the specified op. */
       Pike_error("BSON not valid for the specified op.\n");
     case MONGO_BSON_NOT_FINISHED: /**< BSON object has not been finished. */
       Pike_error("BSON object has not been finished.\n");
     case MONGO_BSON_TOO_LARGE:    /**< BSON object exceeds max BSON size. */
       Pike_error("BSON object exceeds max BSON size.\n");
     case MONGO_WRITE_CONCERN_INVALID: /**< Supplied write concern object is invalid. */
       Pike_error("Supplied write concern object is invalid.\n");
     default:
       Pike_error("unknown error\n");
     
   }
/*
   msg = mongo_get_server_err_string(_db);
   printf("mongodb error: %s\n", msg);
   Pike_error(msg);
*/
 }

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

 /*! @endmodule
  */

 /*! @endmodule
  */



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