/*! \brief Open update cursor \param driver db driver \param table_name table name \param select SQL update statement (?) \param cursor db cursor to be opened \param mode open mode (?) \return DB_OK on success \return DB_FAILED on failure */ int db_open_update_cursor(dbDriver * driver, dbString * table_name, dbString * select, dbCursor * cursor, int mode) { int ret_code; db_init_cursor(cursor); cursor->driver = driver; /* start the procedure call */ db__set_protocol_fds(driver->send, driver->recv); DB_START_PROCEDURE_CALL(DB_PROC_OPEN_UPDATE_CURSOR); /* send the argument(s) to the procedure */ DB_SEND_STRING(table_name); DB_SEND_STRING(select); DB_SEND_INT(mode); /* get the return code for the procedure call */ DB_RECV_RETURN_CODE(&ret_code); if (ret_code != DB_OK) return ret_code; /* ret_code SHOULD == DB_FAILED */ /* get the results */ DB_RECV_TOKEN(&cursor->token); DB_RECV_INT(&cursor->type); DB_RECV_INT(&cursor->mode); DB_RECV_TABLE_DEFINITION(&cursor->table); db_alloc_cursor_column_flags(cursor); return DB_OK; }
/*! \brief Receive datetime \param t pointer to dbDateTime \return DB_OK */ int db__recv_datetime(dbDateTime * t) { DB_RECV_CHAR(&t->current); if (!t->current) { DB_RECV_INT(&t->year); DB_RECV_INT(&t->month); DB_RECV_INT(&t->day); DB_RECV_INT(&t->hour); DB_RECV_INT(&t->minute); DB_RECV_DOUBLE(&t->seconds); } return DB_OK; }
/*! \brief Receive value \param value \param Ctype \return */ int db__recv_value(dbValue * value, int Ctype) { DB_RECV_CHAR(&value->isNull); if (value->isNull) return DB_OK; switch (Ctype) { case DB_C_TYPE_INT: DB_RECV_INT(&value->i); break; case DB_C_TYPE_DOUBLE: DB_RECV_DOUBLE(&value->d); break; case DB_C_TYPE_STRING: DB_RECV_STRING(&value->s); break; case DB_C_TYPE_DATETIME: DB_RECV_DATETIME(&value->t); break; default: db_error(_("send data: invalid C-type")); return DB_FAILED; } return DB_OK; }
/*! \brief Receive table definition \param[out] table \return */ int db__recv_table_definition(dbTable ** table) { int i, ncols; dbTable *t; DB_RECV_INT(&ncols); *table = t = db_alloc_table(ncols); if (t == NULL) return db_get_error_code(); for (i = 0; i < t->numColumns; i++) { DB_RECV_COLUMN_DEFINITION(&t->columns[i]); } DB_RECV_STRING(&t->tableName); DB_RECV_STRING(&t->description); DB_RECV_INT(&t->priv_insert); DB_RECV_INT(&t->priv_delete); return DB_OK; }
int db__recv_index_array(dbIndex ** list, int *count) { int i; DB_RECV_INT(count); *list = db_alloc_index_array(*count); if (*list == NULL) return db_get_error_code(); for (i = 0; i < *count; i++) { DB_RECV_INDEX(&((*list)[i])); } return DB_OK; }
/*! \brief Open select cursor \return DB_OK on success \return DB_FAILED on failure */ int db_d_open_select_cursor(void) { dbCursor *cursor; int stat; dbToken token; dbString select; int mode; /* get the arg(s) */ db_init_string(&select); DB_RECV_STRING(&select); DB_RECV_INT(&mode); /* create a cursor */ cursor = (dbCursor *) db_malloc(sizeof(dbCursor)); if (cursor == NULL) return db_get_error_code(); token = db_new_token((dbAddress) cursor); if (token < 0) return db_get_error_code(); db_init_cursor(cursor); /* call the procedure */ stat = db_driver_open_select_cursor(&select, cursor, mode); db_free_string(&select); /* send the return code */ if (stat != DB_OK) { DB_SEND_FAILURE(); return DB_OK; } DB_SEND_SUCCESS(); /* mark this as a readonly cursor */ db_set_cursor_type_readonly(cursor); /* add this cursor to the cursors managed by the driver state */ db__add_cursor_to_driver_state(cursor); /* results */ DB_SEND_TOKEN(&token); DB_SEND_INT(cursor->type); DB_SEND_INT(cursor->mode); DB_SEND_TABLE_DEFINITION(cursor->table); return DB_OK; }
/*! \brief Receive table data \param table \return */ int db__recv_table_data(dbTable * table) { int i, ncols; ncols = table->numColumns; DB_RECV_INT(&i); if (i != ncols) { db_error(_("fetch: table has wrong number of columns")); return DB_FAILED; } for (i = 0; i < ncols; i++) { DB_RECV_COLUMN_VALUE(db_get_table_column(table, i)); } return DB_OK; }
int db__recv_index(dbIndex * index) { int i, ncols; db_init_index(index); DB_RECV_STRING(&index->indexName); DB_RECV_STRING(&index->tableName); DB_RECV_CHAR(&index->unique); DB_RECV_INT(&ncols); if (db_alloc_index_columns(index, ncols) != DB_OK) return db_get_error_code(); for (i = 0; i < ncols; i++) { DB_RECV_STRING(&index->columnNames[i]); } return DB_OK; }