示例#1
0
int main(int argc, char **argv)
{
     
     SymbolTable* symtbl = create_table(SYMTBL_UNIQUE_NAME);
     SymbolTable* reltbl = create_table(SYMTBL_UNIQUE_NAME);

     FILE* input1  = fopen("myinstr.txt", "r");
     FILE* output1 = fopen("res.txt", "w");
     pass_one(input1, output1, symtbl);

     fclose(input1);
     fclose(output1);
     FILE* input2 = fopen("res.txt", "r");
     FILE* output2 = fopen("final.txt", "w");
     
     pass_two(input2, output2,  symtbl, reltbl);
     
     // int ret = translate_inst(stdout, "addu", args,  3 , 0,  tb1, tb2);
     
     printf("symtbl:\n");
     write_table(symtbl, stdout);
     printf("reltbl:\n");
     write_table(reltbl, stdout);

     free_table(symtbl);
     free_table(reltbl);
     
     fclose(input2);
     fclose(output2);
     return 0;
}
示例#2
0
static const char *create_table_set(struct subdbinfo *info,
				    const char *suffix,
				    int do_mlog)
{
  const char *r;

  /* Address table */
  if ((r = create_table(info,suffix,"",sql_sub_table_defn)) != 0)
    return r;
  /* Subscription log table. */
  if ((r = create_table(info,suffix,"_slog",sql_slog_table_defn)) != 0)
    return r;

  if (do_mlog) {
    /* main list inserts a cookie here. Sublists check it */
    if ((r = create_table(info,suffix,"_cookie",sql_cookie_table_defn)) != 0)
      return r;

    /* main and sublist log here when the message is done done=0 for
     * arrived, done=4 for sent, 5 for receit. */
    if ((r = create_table(info,suffix,"_mlog",sql_mlog_table_defn)) != 0)
      return r;
  }

  return 0;
}
示例#3
0
int main(int argc, char *argv[]) {

  /*
  cube *c0 = cube_edges1(init_cube());
  hash_cube_t h = hash_cube(c0);
  cube *c1 = reconstruct_edges1(&h);
  print_cube(c0);
  print_cube(c1);
  return 0;
  */

  if (argc != 2) {
    fprintf(stderr, "Usage: ./create_table {corners, edges1, edges2}\n");
    return 0;
  }
  if (!strcmp(argv[1], "corners")) {
    create_table(cube_corners, hash_cube, reconstruct_corners, CORNER_NODES);
  } else if (!strcmp(argv[1], "edges1")) {
    create_table(cube_edges1, hash_cube, reconstruct_edges1, EDGE_NODES);
  } else if (!strcmp(argv[1], "edges2")) {
    create_table(cube_edges2, hash_cube, reconstruct_edges2, EDGE_NODES);
  } else {
    fprintf(stderr, "Usage: ./create_table {corners, edge1, edge2}\n");
    return 0;
  }
}
static int dbCreate(Ndb * pNdb)
{
  create_table(SUBSCRIBER_TABLE, create_table_subscriber, pNdb);
  create_table(GROUP_TABLE     , create_table_group, pNdb);
  create_table(SESSION_TABLE   , create_table_session, pNdb);
  create_table(SERVER_TABLE    , create_table_server, pNdb);
  return 0;
}
示例#5
0
static const char *create_table_set(struct subdbinfo *info,
                                    const char *suffix,
                                    int do_mlog)
{
    const char *r;

    /* Address table */
    /* Need varchar. Domain = 3 chars => fixed length, as opposed to
     * varchar Always select on domain and hash, so that one index should
     * do primary key(address) is very inefficient for MySQL.  MySQL
     * tables do not need a primary key. Other RDBMS require one. For the
     * log tables, just add an INT AUTO_INCREMENT. For the address table,
     * do that or use address as a primary key. */
    if ((r = create_table(info,suffix,""," ("
                          "  hash    INT4 NOT NULL,"
                          "  address VARCHAR(255) NOT NULL PRIMARY KEY"
                          ")")) != 0)
        return r;
    /* Subscription log table. No addr idx to make insertion fast, since
     * that is almost the only thing we do with this table */
    if ((r = create_table(info,suffix,"_slog","("
                          "  tai		INTEGER,"
                          "  address	VARCHAR(255) NOT NULL,"
                          "  fromline	VARCHAR(255) NOT NULL,"
                          "  edir		CHAR NOT NULL,"
                          "  etype	CHAR NOT NULL"
                          ")")) != 0)
        return r;

    if (do_mlog) {
        /* main list inserts a cookie here. Sublists check it */
        if ((r = create_table(info,suffix,"_cookie","("
                              "  msgnum		INT4 NOT NULL PRIMARY KEY,"
                              "  tai		INTEGER NOT NULL,"
                              "  cookie		CHAR(20) NOT NULL,"
                              "  chunk		INT4 NOT NULL DEFAULT 0,"
                              "  bodysize	INT4 NOT NULL DEFAULT 0"
                              ")")) != 0)
            return r;

        /* main and sublist log here when the message is done done=0 for
         * arrived, done=4 for sent, 5 for receit.  tai reflects last
         * change */
        if ((r = create_table(info,suffix,"_mlog","("
                              "msgnum	INT4 NOT NULL,"
                              "listno	INT4 NOT NULL,"
                              "tai		TIMESTAMP,"
                              "subs		INT4 NOT NULL DEFAULT 0,"
                              "done		INT4 NOT NULL DEFAULT 0,"
                              "PRIMARY KEY (listno,msgnum,done)"
                              ")")) != 0)
            return r;
    }

    return 0;
}
示例#6
0
文件: test_db.cpp 项目: groonga/grnxx
void test_db() {
  // Create a database with the default options.
  auto db = grnxx::open_db("");
  assert(db->num_tables() == 0);

  // Create a table named "Table_1".
  auto table = db->create_table("Table_1");
  assert(table->name() == "Table_1");
  assert(db->num_tables() == 1);
  assert(db->get_table(0) == table);

  assert(db->find_table("Table_1") == table);
  assert(!db->find_table("Table_X"));

  // The following create_table() must fail because "Table_1" already exists.
  try {
    db->create_table("Table_1");
    assert(false);
  } catch (...) {
  }

  // Create tables named "Table_2" and "Table_3".
  assert(db->create_table("Table_2"));
  assert(db->create_table("Table_3"));
  assert(db->num_tables() == 3);
  assert(db->get_table(0)->name() == "Table_1");
  assert(db->get_table(1)->name() == "Table_2");
  assert(db->get_table(2)->name() == "Table_3");

  // Remove "Table_2".
  db->remove_table("Table_2");
  assert(db->num_tables() == 2);
  assert(db->get_table(0)->name() == "Table_1");
  assert(db->get_table(1)->name() == "Table_3");

  // Recreate "Table_2".
  assert(db->create_table("Table_2"));

  // Move "Table_3" to the next to "Table_2".
  db->reorder_table("Table_3", "Table_2");
  assert(db->get_table(0)->name() == "Table_1");
  assert(db->get_table(1)->name() == "Table_2");
  assert(db->get_table(2)->name() == "Table_3");

  // Move "Table_3" to the head.
  db->reorder_table("Table_3", "");
  assert(db->get_table(0)->name() == "Table_3");
  assert(db->get_table(1)->name() == "Table_1");
  assert(db->get_table(2)->name() == "Table_2");

  // Move "Table_2" to the next to "Table_3".
  db->reorder_table("Table_2", "Table_3");
  assert(db->get_table(0)->name() == "Table_3");
  assert(db->get_table(1)->name() == "Table_2");
  assert(db->get_table(2)->name() == "Table_1");
}
示例#7
0
void test_reference() {
  // Create tables.
  auto db = grnxx::open_db("");
  auto to_table = db->create_table("To");
  auto from_table = db->create_table("From");

  // Create a column named "Ref".
  grnxx::ColumnOptions options;
  options.reference_table_name = "To";
  auto ref_column = from_table->create_column("Ref", GRNXX_INT, options);

  // Append rows.
  to_table->insert_row();
  to_table->insert_row();
  to_table->insert_row();
  from_table->insert_row();
  from_table->insert_row();
  from_table->insert_row();

  ref_column->set(grnxx::Int(0), grnxx::Int(0));
  ref_column->set(grnxx::Int(1), grnxx::Int(1));
  ref_column->set(grnxx::Int(2), grnxx::Int(1));

  // TODO: "from_table" may be updated in "to_table->remove_row()".

  to_table->remove_row(grnxx::Int(0));

  grnxx::Datum datum;
  ref_column->get(grnxx::Int(0), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 0);
  ref_column->get(grnxx::Int(1), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);
  ref_column->get(grnxx::Int(2), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);

  to_table->remove_row(grnxx::Int(1));

  ref_column->get(grnxx::Int(0), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 0);
  ref_column->get(grnxx::Int(1), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);
  ref_column->get(grnxx::Int(2), &datum);
  assert(datum.type() == GRNXX_INT);
  assert(datum.as_int().raw() == 1);
}
示例#8
0
文件: convert.c 项目: snfactory/ifuio
void convert_table(char *in,char *out)
{
  TABLE src,dst;
  int i;

  if (open_table(&src,in,"I")<0) {
    print_error("Cannot open input file %s",in);
    exit_session(ERR_OPEN);
  }
  else
    handle_select_flag(&src,'Q',NULL);

  if (create_table(&dst,out,src.row,src.col,'W',src.ident)<0) {
    close_table(&src);
    print_error("Cannot create output file %s",out);
    exit_session(ERR_CREAT);
  }
  else {
    reset_print_progress();
    for (i=1;i<=src.col;i++) {
      print_progress("Convert table: ", (int)((100*i)/src.col),1);
      copy_col(&src,&dst,i);
    }
	
    CP_non_std_desc(&src,&dst);
	
    close_table(&dst);
    close_table(&src);
  }
}
int main()
{
    struct Table* tbl = create_table();
    insert(tbl,"value0",0);
    insert(tbl,"value1",1);
    insert(tbl,"value2",2);
    print_table(tbl);
    printf("Removing value1\n");
    {
        int val = erase(tbl,"value1");
        printf("value1 had value %d\n",val);
    }
    print_table(tbl);
    {
        int val = find(tbl,"value2");
        printf("value2 has value %d\n",val);
        val = find(tbl,"valuex");
        if (val == -99999)
            printf("can't find valuex\n");
        val = erase(tbl,"valuex");
        if (val == -99999)
            printf("can't erase valuex\n");
    }
    destroy(tbl);
}
// dynamically expand hash table
void expand_table(hash_table *h)
{
	int i, index, new_size;
	
	new_size = next_prime(h->capacity * 2 + 1);

	// create new, expanded hash table
	hash_table *new_table = create_table(new_size);
	
	printf("Hash table before expansion to size %d:\n", new_size);
	print_table(h);
	
	// rehash elements from the old table into the new table
	for (i = 0; i < h->capacity; i++)
	{
		if (h->table[i] != NULL)
		{
			index = get_pos(new_table, *h->table[i]);
			new_table->table[index] = h->table[i];
		
			new_table->size++;
		}
	}
	
	free(h->table);
	
	h->table    = new_table->table;
	h->size     = new_table->size;
	h->capacity = new_table->capacity;
	
	free(new_table);
	
	printf("Hash table after expansion:\n");
	print_table(h);
}
示例#11
0
static void run_application(MYSQL &mysql,
			    Ndb_cluster_connection &cluster_connection,
			    const char* table,
			    const char* db)
{
  /********************************************
   * Connect to database via mysql-c          *
   ********************************************/
 char db_stmt[256];
 sprintf(db_stmt, "CREATE DATABASE %s\n", db);
  mysql_query(&mysql, db_stmt);
 sprintf(db_stmt, "USE %s", db);
  if (mysql_query(&mysql, db_stmt) != 0) MYSQLERROR(mysql);
  create_table(mysql, table);

  /********************************************
   * Connect to database via NdbApi           *
   ********************************************/
  // Object representing the database
  Ndb myNdb( &cluster_connection, db );
  if (myNdb.init()) APIERROR(myNdb.getNdbError());

  /*
   * Do different operations on database
   */
  do_insert(myNdb, table);
  do_update(myNdb, table);
  do_delete(myNdb, table);
  do_read(myNdb, table);
  /*
   * Drop the table
   */
  mysql_query(&mysql, db_stmt);
}
示例#12
0
文件: model.cpp 项目: mrG7/lda
microscopes::lda::state::state(const model_definition &defn,
      float alpha,
      float beta,
      float gamma,
      const microscopes::lda::nested_vector &dish_assignments,
      const microscopes::lda::nested_vector &table_assignments,
      const microscopes::lda::nested_vector &docs)
    : state(defn, alpha, beta, gamma, docs) {
        // Explicit initialization constructor for state used for
        // deserialization and testing
        // table_assignment maps words to tables (and should be the same
        //  shape as docs)
        // dish_assignment maps tables to dishes (its outer length should
        //  be the the same as docs. Its inner length one plus the maximum
        //  table index value for the given entity/doc.)

        // Create all the dishes we will need.
        for(auto dish: lda_util::unique_members(dish_assignments)) {
            create_dish(dish);
        }
        for (size_t eid = 0; eid < nentities(); ++eid) {
            create_entity(eid);
            // Create all the tables we will need and assign them to their dish.
            for(auto did: dish_assignments[eid]){
                create_table(eid, did);
            }
            // Assign words to tables.
            for(size_t word_index = 0; word_index < table_assignments[eid].size(); word_index++){
                auto tid  = table_assignments[eid][word_index];
                add_table(eid, tid, word_index);
            }
        }
}
示例#13
0
void test_set_and_get() {
  constexpr size_t NUM_ROWS = 1 << 16;

  // Create a table and insert the first row.
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");
  auto column = table->create_column("Column", T::type());
  grnxx::Array<T> values;
  values.resize(NUM_ROWS);
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    generate_random_value(&values[i]);
    grnxx::Int row_id = table->insert_row();
    column->set(row_id, values[i]);
    grnxx::Datum datum;
    column->get(row_id, &datum);

    T stored_value;
    datum.force(&stored_value);
    assert(stored_value.match(values[i]));
  }

  // Test all the values again.
  for (size_t i = 0; i < NUM_ROWS; ++i) {
    grnxx::Int row_id = grnxx::Int(i);
    grnxx::Datum datum;
    column->get(row_id, &datum);
    T stored_value;
    datum.force(&stored_value);
    assert(stored_value.match(values[i]));
  }
}
示例#14
0
文件: testdbd.c 项目: cookrn/openamq
static void test_dbd_generic(abts_case *tc, apr_dbd_t* handle, 
                             const apr_dbd_driver_t* driver)
{
    void* native;
    apr_pool_t *pool = p;
    apr_status_t rv;

    native = apr_dbd_native_handle(driver, handle);
    ABTS_PTR_NOTNULL(tc, native);

    rv = apr_dbd_check_conn(driver, pool, handle);

    create_table(tc, handle, driver);
    select_rows(tc, handle, driver, 0);
    insert_data(tc, handle, driver, 5);
    select_rows(tc, handle, driver, 5);
    delete_rows(tc, handle, driver);
    select_rows(tc, handle, driver, 0);
    drop_table(tc, handle, driver);

    test_escape(tc, handle, driver);

    rv = apr_dbd_close(driver, handle);
    ABTS_ASSERT(tc, "failed to close database", rv == APR_SUCCESS);
}
示例#15
0
/*
 * start_workers --
 *     Setup the configuration for the tables being populated, then start
 *     the worker thread(s) and wait for them to finish.
 */
int
start_workers(table_type type)
{
	WT_SESSION *session;
	struct timeval start, stop;
	double seconds;
	pthread_t *tids;
	int i, ret;
	void *thread_ret;

	ret = 0;

	/* Create statistics and thread structures. */
	if ((tids = calloc((size_t)(g.nworkers), sizeof(*tids))) == NULL)
		return (log_print_err("calloc", errno, 1));

	if ((ret = g.conn->open_session(g.conn, NULL, NULL, &session)) != 0) {
		(void)log_print_err("conn.open_session", ret, 1);
		goto err;
	}
	/* Setup the cookies */
	for (i = 0; i < g.ntables; ++i) {
		g.cookies[i].id = i;
		if (type == MIX)
			g.cookies[i].type =
			    (table_type)((i % MAX_TABLE_TYPE) + 1);
		else
			g.cookies[i].type = type;
		(void)snprintf(g.cookies[i].uri, 128,
		    "%s%04d", URI_BASE, g.cookies[i].id);

		/* Should probably be atomic to avoid races. */
		if ((ret = create_table(session, &g.cookies[i])) != 0)
			goto err;
	}

	(void)gettimeofday(&start, NULL);

	/* Create threads. */
	for (i = 0; i < g.nworkers; ++i) {
		if ((ret = pthread_create(
		    &tids[i], NULL, worker, &g.cookies[i])) != 0) {
			(void)log_print_err("pthread_create", ret, 1);
			goto err;
		}
	}

	/* Wait for the threads. */
	for (i = 0; i < g.nworkers; ++i)
		(void)pthread_join(tids[i], &thread_ret);

	(void)gettimeofday(&stop, NULL);
	seconds = (stop.tv_sec - start.tv_sec) +
	    (stop.tv_usec - start.tv_usec) * 1e-6;
	printf("Ran workers for: %f seconds\n", seconds);

err:	free(tids);

	return (ret);
}
示例#16
0
void MYMENU_FileOpen()
{
    OPENFILENAMEA ofn;
    ZeroMemory( &ofn, sizeof( ofn ) );
    
    ofn.lStructSize = sizeof( ofn ); // SEE NOTE BELOW
    ofn.hwndOwner = hwnd;
    ofn.lpstrFilter = "CSV Files (*.csv)\0*.csv\0Kiss Files (*.kiss)\0*.kiss\0All Files (*.*)\0*.*\0";
    ofn.lpstrFile = szFileName;
    ofn.nMaxFile = MAX_PATH;
    ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
    ofn.lpstrDefExt = "csv";
    
    if ( GetOpenFileName( &ofn ) ) {
        if ( prompt_save_changes() ) {
            FILE* fp = fopen( szFileName, "r" );
            if ( fp == NULL )
                return;
            free_table( table );
            free_history();
            // parse
            table = create_table();
            if ( strncmp( ofn.lpstrFile + ofn.nFileExtension, "csv", 3 ) == 0 )
                import_csv( fp, table );
            else if ( strncmp( ofn.lpstrFile + ofn.nFileExtension, "kiss", 4 ) == 0 )
                import_kiss( fp, table );
            fclose( fp );
            set_caption( szFileName );
            auto_adapt_layout( table );
            update_selection_rect();
            update_table_view( hwnd );
            unsaved = 0;
        }
    }
}
示例#17
0
static int __init init_tagfs_fs(void)
{
	printk("Loading tagfs kernel module\n");
	install_syscalls();
	table = create_table();
	return register_filesystem(&tagfs_fs_type);
}
示例#18
0
int GP_FilterTablesInit(GP_FilterTables *self, const GP_Context *ctx)
{
	unsigned int i;
	const GP_PixelTypeDescription *desc;

	GP_DEBUG(2, "Allocating tables for pixel %s",
	         GP_PixelTypeName(ctx->pixel_type));

	for (i = 0; i < GP_PIXELTYPE_MAX_CHANNELS; i++)
		self->table[i] = NULL;

	desc = GP_PixelTypeDesc(ctx->pixel_type);

	for (i = 0; i < desc->numchannels; i++) {
		self->table[i] = create_table(&desc->channels[i]);
		if (!self->table[i]) {
			free_tables(self);
			return 1;
		}
	}

	self->free_table = 0;

	return 0;
}
示例#19
0
void TableDialog::setup(Data _data, Table _tableInfo, vector<Attribute> _column)
{
    dataInfo = _data;
    tableInfo = _tableInfo;
    column = _column;
    create_table();
}
示例#20
0
region_table_t *parse_regions_from_gff_file(char *filename, const char *url, const char *species, const char *version) {
    gff_file_t *file = gff_open(filename);
    if (file == NULL) {
        return NULL;
    } 
    
    region_table_t *regions_table = create_table(url, species, version);
    
    int ret_code = 0;
    size_t max_batches = 20;
    size_t batch_size = 2000;
    list_t *read_list = (list_t*) malloc (sizeof(list_t));
    list_init("batches", 1, max_batches, read_list);
    
    #pragma omp parallel sections
    {
        // The producer reads the GFF file
        #pragma omp section
        {
            LOG_DEBUG_F("Thread %d reads the GFF file\n", omp_get_thread_num());
            ret_code = gff_read_batches(read_list, batch_size, file);
            list_decr_writers(read_list);
            
            if (ret_code) {
                LOG_FATAL_F("Error while reading GFF file %s (%d)\n", filename, ret_code);
            }
        }
        
        // The consumer inserts regions in the structure 
        #pragma omp section
        {    
            list_item_t *item = NULL, *batch_item = NULL;
            gff_batch_t *batch;
            gff_record_t *record;
            while ( (item = list_remove_item(read_list)) != NULL ) {
                batch = item->data_p;
                // For each record in the batch, generate a new region
                for (batch_item = batch->first_p; batch_item != NULL; batch_item = batch_item->next_p) {
                    record = batch_item->data_p;
                    
                    region_t *region = (region_t*) malloc (sizeof(region_t));
                    region->chromosome = (char*) calloc ((strlen(record->sequence)+1), sizeof(char));
                    strncat(region->chromosome, record->sequence, strlen(record->sequence));
                    region->start_position = record->start;
                    region->end_position = record->end;
                    LOG_DEBUG_F("region '%s:%u-%u'\n", region->chromosome, region->start_position, region->end_position);
                    
                    insert_region(region, regions_table);
                }
               
                gff_batch_free(item->data_p);
                list_item_free(item);
            }
        }
    }
    
    gff_close(file, 0);
    
    return regions_table;
}
示例#21
0
int main(int argc, char *argv[]){
  cmdline::parser p;

  try{
    //    p.add<T>("long option", 'short option', 'help message', 'must need?', 'default' , CustomReader)
    p.add<int>("scale-factor", 'w', "( 1 - 32 )", false, 1, cmdline::range(1, 32));
    p.add<std::string>("table", 't', "( warehouse | district | history | new-order | order | item | stock | customer )", false, "", cmdline::oneof<std::string>("warehouse", "district", "history", "new-order", "order", "item", "stock", "customer"));
    p.add("help", 0, "print help");

    p.parse_check(argc, argv);

    if(p.exist("scale-factor")){
      W = p.get<int>("scale-factor");
    } else {
      W = 1;
    }

    if(p.exist("table")){
      create_table(p.get<std::string>("table"));
    } else {
      create_all();
    }
  } catch(std::exception e) {
    std::cerr << e.what() << std::endl;
  }

  return 0;
}
示例#22
0
int gp_filter_tables_init(gp_filter_tables *self, const gp_pixmap *pixmap)
{
	unsigned int i;
	const gp_pixel_type_desc *desc;

	GP_DEBUG(2, "Allocating tables for pixel %s",
	         gp_pixel_type_name(pixmap->pixel_type));

	for (i = 0; i < GP_PIXELTYPE_MAX_CHANNELS; i++)
		self->table[i] = NULL;

	desc = gp_pixel_desc(pixmap->pixel_type);

	for (i = 0; i < desc->numchannels; i++) {
		self->table[i] = create_table(&desc->channels[i]);
		if (!self->table[i]) {
			free_tables(self);
			return 1;
		}
	}

	self->free_table = 0;

	return 0;
}
示例#23
0
void Parser::process_command(InputType type)
{
	switch (type){
	case CREATE_:
		create_table();
		break;
	case INSERT_:
		insert_into();
		break;
	case OPEN_:
		open();
		break;
	case CLOSE_:
		close();
		break;
	case WRITE_:
		write();
		break;
	case SHOW_:
		show();
		break;
	case EXIT_:
		exit();
		break;
	case DELETE_:
		delete_from();
		break;
	case UPDATE_:
		update_to();
		break;
	default:
		break;
	}

}
示例#24
0
static void run_application(MYSQL &mysql,
			    Ndb_cluster_connection &cluster_connection)
{
  /********************************************
   * Connect to database via mysql-c          *
   ********************************************/
  mysql_query(&mysql, "CREATE DATABASE TEST_DB_1");
  if (mysql_query(&mysql, "USE TEST_DB_1") != 0) MYSQLERROR(mysql);
  create_table(mysql);

  /********************************************
   * Connect to database via NdbApi           *
   ********************************************/
  // Object representing the database
  Ndb myNdb( &cluster_connection, "TEST_DB_1" );
  if (myNdb.init()) APIERROR(myNdb.getNdbError());

  /*
   * Do different operations on database
   */
  do_insert(myNdb);
  do_update(myNdb);
  do_delete(myNdb);
  do_read(myNdb);
  drop_table(mysql);
  mysql_query(&mysql, "DROP DATABASE TEST_DB_1");
}
示例#25
0
bool latency::create_tbl() {
	if(create_table(m_xtablename, m_createstmt, m_xhost, m_xusername, m_xpassword, m_xdbname) == true)
		return true;

	LOG4CXX_ERROR("m_config.at(\"harmonics.db.latency.query.create\")");
	return false;
}
示例#26
0
void test_basic_operations(const T &value) {
  constexpr grnxx::DataType data_type = T::type();

  // Create a table and insert the first row.
  auto db = grnxx::open_db("");
  auto table = db->create_table("Table");
  grnxx::Int row_id = table->insert_row();

  // Create a column named "Column".
  auto column = table->create_column("Column", data_type);
  assert(column->table() == table);
  assert(column->name() == "Column");
  assert(column->data_type() == data_type);
  assert(!column->reference_table());
  assert(!column->is_key());
  assert(column->num_indexes() == 0);

  // Check if N/A is stored or not.
  grnxx::Datum datum;
  T stored_value;
  column->get(row_id, &datum);
  assert(datum.type() == data_type);
  datum.force(&stored_value);
  assert(stored_value.is_na());

  // Set a value and get it.
  column->set(row_id, value);
  column->get(row_id, &datum);
  assert(datum.type() == data_type);
  datum.force(&stored_value);
  assert(stored_value.match(value));
}
示例#27
0
int main() {
	SQLTable *table = (SQLTable *) malloc(sizeof(SQLTable));
	const string colname[16] = {"lastname", "firstname", "ID", "salary", "age"};
	const DATATYPE coltype[5] = {STRING, STRING, STRING, INT, INT};
	create_table(table, colname, coltype, 5);
	
	int N, Q;
	scanf("%d", &N);
	
	table->rowsize = N;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < 3; j++)
			scanf("%s", &(table->data[i]).fields[j].d.str.c_str);
		for (int j = 3; j < 5; j++)
			scanf("%d", &((table->data[i]).fields[j].d.num));
	}
	scanf("%d", &Q);
	while (getchar() != '\n');
	
	char cmd[1024];
	for (int i = 0; i < Q; i++) {
		fgets(cmd, 1024, stdin);
		table->SQLquery(table, cmd);
	}
	return 0;
}
CTbDeleteFileRecord::CTbDeleteFileRecord(const char *db_path)
{
	try
	{
		m_psqlite_engine = new CSqliteEngine(db_path);
	}
	catch(std::bad_alloc)
	{
		m_psqlite_engine = NULL;
		KL_SYS_ERRORLOG("file: "__FILE__", line: %d, " \
			"no more memory to create sqilte engine", \
			__LINE__);
		throw ENOMEM;
	}
	catch(const char *perrmsg)
	{
		m_psqlite_engine = NULL;
		KL_SYS_ERRORLOG("file: "__FILE__", line: %d, " \
			"tb_hash_code create sqlite engine failed, err: %s", \
			__LINE__, perrmsg);
		throw perrmsg;
	}

	if(create_table() != 0)
	{
		throw "create table tb_delete_file_record failed";
	}
}
示例#29
0
/**
 * @brief init database
 * @param char* database name
 * @param char* table name
 * @param bool simulate date
 */
void init_database(const char *database, const char *table, bool simulate = false) {
	char data[256];							/**< pointer to data  */

	// init and reserve memory
	db = mysql_init(NULL);
	check_error();
	printf("initialize...\n");

	// database connect
	mysql_real_connect(db, HOST, USER, PASSWORD, NULL, 0, NULL, 0);
	check_error();
	printf("connect  success\n");

	create_database(database);

	// selectt db
	mysql_select_db(db, database);
	check_error();
	printf("select success\n");

	// create table
	create_table(table);

	if(simulate) {
		insert_sim_data(table);
	}
}
示例#30
0
void db_multi_key_data::clear() {
    int rc = 0;
    char* szErrMsg = 0;
    {
        boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
        if (need_mutex_) local_lock_.lock();
        rc = sqlite3_exec(
                 db_,
                 "DROP TABLE IF EXISTS data_header",
                 NULL,
                 0,
                 &szErrMsg);
        if (rc != SQLITE_OK) {
            std::stringstream ss("");
            ss << "SQL error in DROP table : ";
            ss << szErrMsg;
            sqlite3_free(szErrMsg);
            local_lock_.unlock();
            throw std::runtime_error(ss.str());
        }
    }
    {
        boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
        if (need_mutex_) local_lock_.lock();
        rc = sqlite3_exec(
                 db_,
                 "DROP TABLE IF EXISTS data_time",
                 NULL,
                 0,
                 &szErrMsg);
        if (rc != SQLITE_OK) {
            std::stringstream ss("");
            ss << "SQL error in DROP table : ";
            ss << szErrMsg;
            sqlite3_free(szErrMsg);
            local_lock_.unlock();
            throw std::runtime_error(ss.str());
        }
    }
    {
        boost::mutex::scoped_lock lock_it(local_lock_, boost::defer_lock);
        if (need_mutex_) local_lock_.lock();
        rc = sqlite3_exec(
                 db_,
                 "DROP TABLE IF EXISTS data_item",
                 NULL,
                 0,
                 &szErrMsg);
        if (rc != SQLITE_OK) {
            std::stringstream ss("");
            ss << "SQL error in DROP table : ";
            ss << szErrMsg;
            sqlite3_free(szErrMsg);
            local_lock_.unlock();
            throw std::runtime_error(ss.str());
        }
    }
    create_table();
}