Esempio n. 1
0
/* @return 0 if error occurs, else the id of table                           */
uint8_t dbms_select(uint8_t table_id, uint8_t scheme[], uint8_t size)
{
    // get old database
    database *db = db_list_get_table(table_id);

    // unknown id
	if(!db) {
#ifdef DEBUG_DBMS
		printf("ERROR: dbms_select: unknown table with id %d!\n\r", table_id);
#endif //DEBUG_DBMS
		return 0;
	}

    // create new database
    database *new_db = db_select(table_id, db, scheme, size);

    // memory full
	if(!new_db) {
#ifdef DEBUG_DBMS
		printf("ERROR: dbms_select: error while creating new database!\n\r");
#endif //DEBUG_DBMS
		return 0;
	}

    // replace old database with new
    db_drop(db_list_remove_table(table_id));
    db_list_add_table(new_db);

    return table_id;
}
Esempio n. 2
0
/*
 * orp_oid_delete - 
 *    return:
 *    pool():
 *    xoid():
 */
static int
orp_oid_delete (API_OBJECT_RESULTSET_POOL * pool, CI_OID * xoid)
{
  OBJECT_RESULTSET_POOL *p;
  OID oid;
  int res;
  void *r;

  assert (pool != NULL);
  assert (xoid != NULL);
  p = (OBJECT_RESULTSET_POOL *) pool;
  /* delete object resultset */
  xoid2oid (xoid, &oid);
  res = hash_lookup (p->ht, &oid, &r);
  if (res != NO_ERROR)
    return res;
  if (r)
    {
      OBJECT_RESULTSET *or = (OBJECT_RESULTSET *) r;
      DB_OBJECT *obj = or->obj;
      assert (obj != NULL);
      assert (or->res_bind != NULL);
      or->res_bind->res.ifs->destroy ((API_RESULTSET *) or->res_bind);
      (void) db_drop (obj);
      return NO_ERROR;
    }
  return ER_INTERFACE_INVALID_HANDLE;
}
Esempio n. 3
0
/*
 * res_api_delete_row - 
 *    return:
 *    impl():
 */
static int
res_api_delete_row (API_RESULTSET * impl)
{
  OBJECT_RESULTSET *or;
  int res;

  assert (impl != NULL);
  or = ((OBJECT_RES_BIND *) impl)->or;
  if (or->deleted == 1)
    return ER_INTERFACE_GENERIC;	/* already deleted */
  res = db_drop (or->obj);
  if (res != NO_ERROR)
    return ER_INTERFACE_GENERIC;
  or->vt->ifs->destroy (or->vt);
  or->vt = NULL;
  or->deleted = 1;
  return NO_ERROR;
}
Esempio n. 4
0
int main(int argc, char* argv[]) 
{ 
    sqlite3 * db; 
    int i; 
    COLUMN column[10]; 
    pTable_name = table_name; 
    strcpy(pTable_name, "test_table"); 
 
    ret = sqlite3_open("student.db", &db); 
    if(ret != SQLITE_OK) 
    { 
        perror("slqite3_open"); 
        exit(1); 
    } 
 
    while(choice != 0) 
    { 
	printf("please input your choise:\n"); 
	printf("-------------------------------------\n"); 
	printf("|0.exit|1.create|2.show|3.insert|4.update|5.delete|6.empty|7.drop|\n"); 
	printf("-------------------------------------\n"); 
        scanf("%d", &choice); 
        
        switch(choice) 
        { 
            case 0: 
	printf("you choise leave, y or n?\n"); 
                    setbuf(stdin, NULL); 
                    scanf("%c", &c); 
                    setbuf(stdin, NULL); 
                    if(c == 'y') 
                    { 
                        if(test_flag == 0) 
                        { 
	db_drop(db, "test_table", &test_flag, &create_flag); 
                        } 
                        
                        printf("goodbye!\n"); 
 
                        sqlite3_close(db); 
 
                        return 0; 
                    } 
                    else 
                    { 
                        choice = -1; 
                    } 
 
                    break; 
                    
            case 1: 
		printf("we will create a table for you, please input the name of your table:\n"); 
		scanf("%s",pTable_name); 
		printf("please input the number of column:\n"); 
		scanf("%d", &column_num); 
		printf("please input column_name column_type:\n"); 
 
		for(i = 0; i < column_num; i++)
		  scanf("%s %s", column[i].column_name, column[i].column_type);                        
		 
		db_create(db, table_name, column_num, column, &create_flag); 
				    break; 
            case 2: 
		db_flag(db, &create_flag, &test_flag, table_name); 
		db_show(db, table_name); 
				    break; 
                   
            case 3: 
		db_flag(db, &create_flag, &test_flag, table_name); 
		db_insert(db, table_name, column_num, column, &test_flag, &create_flag); 
				    break; 
            case 4: 
		db_flag(db, &create_flag, &test_flag, table_name); 
		db_update(db, table_name, column_num, column, &test_flag, &create_flag); 
				    break; 
            case 5: 
                    db_flag(db, &create_flag, &test_flag, table_name); 
                    db_delete(db, table_name); 
                    break; 
            case 6: 
                    db_flag(db, &create_flag, &test_flag, table_name); 
                    db_empty(db, table_name); 
                    break; 
            case 7: 
                    db_flag(db, &create_flag, &test_flag, table_name); 
                    db_drop(db, table_name, &test_flag, &create_flag); 
                    break; 
            default: 
                    printf("your choice is not exist!\n"); 
                    break; 
    
        } 
        
    } 
 
	sqlite3_close(db); 
    return 0; 
}