static int drop_expire_tables(void) { if (settings.data_keep_time == 0) return 0; int i; for (i = 0; i < settings.hash_table_num; ++i) { char *table_name = get_table_name(i, -settings.data_keep_time); if (table_name == NULL) return -__LINE__; NEG_RET(drop_table(table_name)); } if (settings.hash_table_num > 1 && strcasecmp(settings.db_engine, "myisam") == 0) { char *merge_table = get_table_name(-1, -settings.data_keep_time); if (merge_table == NULL) return -__LINE__; NEG_RET(drop_table(merge_table)); } return 0; }
int main( int argc, char *argv[]) { Arb_connection *conn; int rc; int nullable = 1; get_env_param( argc, argv, 0, Global_dbinfo.server, Global_dbinfo.database, Global_dbinfo.user, Global_dbinfo.password); strcpy( Global_dbinfo.application, __FILE__); rc = arb_database_login( Global_dbinfo.server, Global_dbinfo.database, Global_dbinfo.user, Global_dbinfo.password, Global_dbinfo.application, ALLOW_BCP, &conn); drop_table( conn, TABLENAME); printf( "Creating table.\n"); nullable = 1; make_database_table( conn, TABLENAME, "rowid", "integer", ARB_TYPE_INT32, nullable, "firstname", "string", 57, nullable, "lastname", "string", 57, nullable, "weight", "Arb_numeric", 6, nullable, "birthday", "Arb_date", ARB_TYPE_DATELONG, nullable, NULL); arb_close(conn,1); return 0; }
int main( int argc, char *argv[]) { Arb_connection *conn = NULL; int rc; int i; char server[128]; char database[128]; /* schema */ char user[128]; char password[128]; char application[128]; char infile[256]; Widget widgets[ARRSZ]; short iind[ARRSZ][MAX_TBL_COLS]; memset( widgets, 0, sizeof(widgets)); memset( iind, 0, sizeof(iind)); get_env_param( argc, argv, 0, server, database, user, password); strcpy( application, __FILE__); #if 0 printf( "server = '%s'\n" "database = '%s'\n" "user = '******'\n" "password = '******'\n" "application = '%s'\n", server, database, user, password, application); #endif init_DLAYER_THREAD(); rc = arb_database_login( server, database, user, password, application, ALLOW_BCP, &conn); if( rc == SUCCESS) puts( "Login successful."); else { puts( "Login failed."); exit(1); } drop_table( conn, TABLENAME); create_testcols_table( conn); create_insert_procedure( conn); populate_table( conn, widgets); arb_close(conn,1); exit_DLAYER_THREAD(); return 0; }
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); }
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"); }
void setup(sqlite3* db) { const char* sql; log_sql(db, 1); printf("Dropping table types, if exists.\n"); drop_table(db, "types"); printf("Creating table types.\n"); sql = "create table types(\n" "id integer primary key, " "x int not null default 0," "y float not null default 0.0);"; execute(db, sql); printf("Populating table types.\n"); execute(db, "insert into types(x,y) values (1, 1.1)"); execute(db, "insert into types(x,y) values (2, 2.1)"); execute(db, "insert into types(x,y) values (3, 3.1)"); log_sql(db, 0); printf("\n"); }
void check_results(OCI_Connection *con, OCI_DirPath *dp, int expected, int result, char *str) { if (result != expected) { printf("FAILED : %s - expected %d - result %d\n", str, expected, result); OCI_DirPathFree(dp); drop_table(con); OCI_ConnectionFree(con); OCI_Cleanup(); exit(EXIT_FAILURE); } }
int main( int argc, char *argv[]) { Arb_connection *conn = NULL; int rc; int i; char server[128]; char database[128]; /* schema */ char user[128]; char password[128]; char application[128]; char infile[256]; get_env_param( argc, argv, 0, server, database, user, password); strcpy( application, __FILE__); #if 0 printf( "server = '%s'\n" "database = '%s'\n" "user = '******'\n" "password = '******'\n" "application = '%s'\n", server, database, user, password, application); #endif init_DLAYER_THREAD(); rc = arb_database_login( server, database, user, password, application, ALLOW_BCP, &conn); if( rc == SUCCESS) puts( "Login successful."); else { puts( "Login failed."); exit(1); } drop_table( conn, TABLENAME); create_testcols_table( conn); arb_close(conn,1); exit_DLAYER_THREAD(); return 0; }
void create_table(MYSQL &mysql) { if (try_create_table(mysql)) { if (mysql_errno(&mysql) != ER_TABLE_EXISTS_ERROR) MYSQLERROR(mysql); std::cout << "MySQL Cluster already has example table: api_blob_ndbrecord. " << "Dropping it..." << std::endl; /****************** * Recreate table * ******************/ drop_table(mysql); if (try_create_table(mysql)) MYSQLERROR(mysql); } }
/********************************************************* * Create a table named api_async1 if it does not exist * *********************************************************/ static void create_table(MYSQL &mysql) { while(mysql_query(&mysql, "CREATE TABLE api_async1" " (ATTR1 INT UNSIGNED NOT NULL PRIMARY KEY," " ATTR2 INT UNSIGNED NOT NULL)" " ENGINE=NDB")) { if (mysql_errno(&mysql) == ER_TABLE_EXISTS_ERROR) { std::cout << "MySQL Cluster already has example table: api_scan. " << "Dropping it..." << std::endl; drop_table(mysql); } else MYSQLERROR(mysql); } }
/** * Function to create table */ void create_table(MYSQL &mysql) { while (mysql_query(&mysql, "CREATE TABLE" " api_scan" " (REG_NO INT UNSIGNED NOT NULL," " BRAND CHAR(20) NOT NULL," " COLOR CHAR(20) NOT NULL," " PRIMARY KEY USING HASH (REG_NO))" " ENGINE=NDB")) { if (mysql_errno(&mysql) != ER_TABLE_EXISTS_ERROR) MYSQLERROR(mysql); std::cout << "MySQL Cluster already has example table: api_scan. " << "Dropping it..." << std::endl; drop_table(mysql); } }
void create_table(OCI_Connection *con) { /* create a partitioned table (for loading error) */ boolean res = OCI_ImmediateFmt(con, "create table %m(val_int int not null, val_str varchar2(30), val_date date) partition by range(val_int) ( partition test_dp_1 values less than (501), partition test_dp_2 values less than (1001))", TABLE_NAME); /* in case partitioning is not available, create a regular table and disable loading errtests */ if (!res) { partionning_enabled = FALSE; res = OCI_ImmediateFmt(con, "create table %m(val_int int not null, val_str varchar2(30), val_date date)", TABLE_NAME); } /* exit tests if table cannot be created */ if (!res) { printf("FAILED : table cannot be created\n"); drop_table(con); OCI_ConnectionFree(con); OCI_Cleanup(); exit(EXIT_FAILURE); } }
int _exec_stmt(DB * db, stmt_t * stmt) { switch (stmt->type) { case STMT_CREAT_TABLE: return create_table(db, stmt->table, stmt->cols, stmt->ncol); case STMT_DROP_TABLE: return drop_table(db, stmt->table); case STMT_CREAT_INDEX: return create_index(db, stmt->table, stmt->attr, stmt->index); case STMT_DROP_INDEX: return drop_index(db, stmt->index); case STMT_INSERT: return insert_into(db, stmt->table, NULL, stmt->vals, stmt->nval); case STMT_DELETE: return delete_from(db, stmt->table, stmt->conds, stmt->ncond); case STMT_SELECT: return select_and_print(db, stmt->table, stmt->cols, stmt->ncol, stmt->conds, stmt->ncond); } xerrno = ERR_INVSTMT; return -1; }
int main(int argc, char* argv[]) { ib_err_t err; print_version(); err = ib_init(); assert(err == DB_SUCCESS); test_configure(); #ifndef __WIN__ set_options(argc, argv); #endif err = ib_startup("barracuda"); assert(err == DB_SUCCESS); err = test_phase_I(); if (err == DB_SUCCESS) { restart(argc, argv); /* Shouldn't get here. */ abort(); } else { /* Recovery was successful. */ assert(err == DB_DUPLICATE_KEY); err = drop_table(DATABASE, TABLE); assert(err == DB_SUCCESS); err = ib_shutdown(IB_SHUTDOWN_NORMAL); assert(err == DB_SUCCESS); } return(EXIT_SUCCESS); }
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 */ drop_table(mysql, table); sprintf(db_stmt, "DROP DATABASE %s\n", db); mysql_query(&mysql, db_stmt); }
int main(int argc, char* argv[]) { ib_err_t err; ib_crsr_t crsr; ib_trx_t ib_trx; (void) argc; (void) argv; err = ib_init(); assert(err == DB_SUCCESS); test_configure(); err = ib_startup("barracuda"); assert(err == DB_SUCCESS); err = create_database(DATABASE); assert(err == DB_SUCCESS); err = create_table(DATABASE, TABLE); assert(err == DB_SUCCESS); ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ); assert(ib_trx != NULL); err = open_table(DATABASE, TABLE, ib_trx, &crsr); assert(err == DB_SUCCESS); err = ib_cursor_lock(crsr, IB_LOCK_IX); assert(err == DB_SUCCESS); err = insert_random_rows(crsr); assert(err == DB_SUCCESS); err = ib_cursor_close(crsr); assert(err == DB_SUCCESS); crsr = NULL; err = ib_trx_commit(ib_trx); assert(err == DB_SUCCESS); err = create_sec_index_1(DATABASE, TABLE); assert(err == DB_SUCCESS); err = test_create_temp_index(DATABASE, TABLE, "c2"); err = open_sec_index_1(DATABASE, TABLE); assert(err == DB_SUCCESS); err = drop_table(DATABASE, TABLE); assert(err == DB_SUCCESS); err = ib_shutdown(IB_SHUTDOWN_NORMAL); assert(err == DB_SUCCESS); #ifdef UNIV_DEBUG_VALGRIND VALGRIND_DO_LEAK_CHECK; #endif return(EXIT_SUCCESS); }
int main(int argc, char* argv[]) { int i; ib_err_t err; ib_crsr_t crsr; ib_trx_t ib_trx; #ifdef __WIN__ srand((int) time(NULL)); #else srandom(time(NULL)); #endif err = ib_init(); assert(err == DB_SUCCESS); test_configure(); #ifndef __WIN__ set_options(argc, argv); #endif /* __WIN__ */ err = ib_startup("barracuda"); assert(err == DB_SUCCESS); err = create_database(DATABASE); assert(err == DB_SUCCESS); for (i = 0; i < 10; ++i) { int j; printf("Create table\n"); err = create_table(DATABASE, TABLE); assert(err == DB_SUCCESS); for (j = 0; j < 10; ++j) { ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ); assert(ib_trx != NULL); err = open_table(DATABASE, TABLE, ib_trx, &crsr); assert(err == DB_SUCCESS); err = ib_cursor_lock(crsr, IB_LOCK_IX); assert(err == DB_SUCCESS); insert_random_rows(crsr); update_random_rows(crsr); err = ib_cursor_close(crsr); assert(err == DB_SUCCESS); crsr = NULL; err = ib_trx_commit(ib_trx); assert(err == DB_SUCCESS); } printf("Drop table\n"); err = drop_table(DATABASE, TABLE); assert(err == DB_SUCCESS); } err = ib_shutdown(IB_SHUTDOWN_NORMAL); assert(err == DB_SUCCESS); #ifdef UNIV_DEBUG_VALGRIND VALGRIND_DO_LEAK_CHECK; #endif return(EXIT_SUCCESS); }
int main(int argc, char** argv) { if (argc != 3) { std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; exit(-1); } char * mysqld_sock = argv[1]; const char *connectstring = argv[2]; ndb_init(); MYSQL mysql; /************************************************************** * Connect to mysql server and create table * **************************************************************/ { if ( !mysql_init(&mysql) ) { std::cout << "mysql_init failed\n"; exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", 0, mysqld_sock, 0) ) MYSQLERROR(mysql); mysql_query(&mysql, "CREATE DATABASE TEST_DB"); if (mysql_query(&mysql, "USE TEST_DB") != 0) MYSQLERROR(mysql); create_table(mysql); } /************************************************************** * Connect to ndb cluster * **************************************************************/ Ndb_cluster_connection cluster_connection(connectstring); if (cluster_connection.connect(4, 5, 1)) { std::cout << "Unable to connect to cluster within 30 secs." << std::endl; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster_connection.wait_until_ready(30,0) < 0) { std::cout << "Cluster was not ready within 30 secs.\n"; exit(-1); } Ndb* myNdb = new Ndb( &cluster_connection, "TEST_DB" ); // Object representing the database if (myNdb->init(1024) == -1) { // Set max 1024 parallel transactions APIERROR(myNdb->getNdbError()); } /** * Initialise transaction array */ for(int i = 0 ; i < 10 ; i++) { transaction[i].used = 0; transaction[i].conn = 0; } int i=0; /** * Do 10 insert transactions. */ while(i < 10) { while(populate(myNdb,i,0)<0) // <0, no space on free list. Sleep and try again. milliSleep(10); i++; } std::cout << "Number of temporary errors: " << tempErrors << std::endl; delete myNdb; drop_table(mysql); }
/* ** Create the three CVS tables if not already there ** location: filename, id ** user: username, id ** log: user_id, location_id, date, operation, message */ PRIVATE BOOL createTables (HTSQL * sql, SQLFlags flags) { if (sql) { char buf[1024]; char * query = NULL; /* Create location table */ /* If we have to delete it first */ if (flags & SQL_DROP_LOCATION_TABLE) drop_table(sql, DEFAULT_SQL_LOCATION_TABLE); query = HTSQL_printf(buf, 1024, "create table %s (id %s auto_increment, location varchar(%u) binary not null, primary key(id), unique(location), index loc_idx(location(32)))", DEFAULT_SQL_LOCATION_TABLE, DEFAULT_SQL_KEY_TYPE, MAX_KEY_LENGTH); HTSQL_query(sql, query); /* If we have to clear it out */ if (flags & SQL_CLEAR_LOCATION_TABLE) clear_table(sql, DEFAULT_SQL_LOCATION_TABLE); /* Create user table */ /* If we have to delete it first */ if (flags & SQL_DROP_USER_TABLE) drop_table(sql, DEFAULT_SQL_USER_TABLE); query = HTSQL_printf(buf, 1024, "create table %s (id %s auto_increment, username varchar(%u) binary not null, primary key(id), unique(username), index username_idx(username(32)))", DEFAULT_SQL_USER_TABLE, DEFAULT_SQL_KEY_TYPE, MAX_KEY_LENGTH); HTSQL_query(sql, query); /* If we have to clear it out */ if (flags & SQL_CLEAR_USER_TABLE) clear_table(sql, DEFAULT_SQL_USER_TABLE); /* Create comments table */ /* If we have to delete it first */ if (flags & SQL_DROP_COMMENTS_TABLE) drop_table(sql, DEFAULT_SQL_COMMENTS_TABLE); query = HTSQL_printf(buf, 1024, "create table %s (id %s auto_increment, comment text, primary key(id))", DEFAULT_SQL_COMMENTS_TABLE, DEFAULT_SQL_KEY_TYPE); HTSQL_query(sql, query); /* If we have to clear it out */ if (flags & SQL_CLEAR_COMMENTS_TABLE) clear_table(sql, DEFAULT_SQL_COMMENTS_TABLE); /* Create logs table */ /* If we have to delete it first */ if (flags & SQL_DROP_LOG_TABLE) drop_table(sql, DEFAULT_SQL_LOG_TABLE); query = HTSQL_printf(buf, 1024, "create table %s (location %s, username %s, date datetime, operation char(32), comment %s)", DEFAULT_SQL_LOG_TABLE, DEFAULT_SQL_KEY_TYPE, DEFAULT_SQL_KEY_TYPE, DEFAULT_SQL_KEY_TYPE); HTSQL_query(sql, query); /* If we have to clear it out */ if (flags & SQL_CLEAR_LOG_TABLE) clear_table(sql, DEFAULT_SQL_LOG_TABLE); /* All done */ return YES; } return NO; }
void do_load(OCI_Connection *con, boolean gen_conv_error, boolean gen_load_error, boolean gen_buffer_error, boolean force, char *test_name) { OCI_DirPath *dp; char val1[SIZE_COL1 + 1]; char val2[SIZE_COL2 + 1]; char val3[SIZE_COL3 + 1]; int i = 0, j = 0, nb_rows = SIZE_ARRAY; printf("%s : ", test_name); /* create table */ create_table(con); /* create direct object */ dp = OCI_DirPathCreate(OCI_TypeInfoGet(con, TABLE_NAME, OCI_TIF_TABLE), NULL, NUM_COLS, nb_rows); /* optional attributes to set */ OCI_DirPathSetBufferSize(dp, gen_buffer_error ? 100 : 64000); OCI_DirPathSetConvertMode(dp, force ? OCI_DCM_FORCE : OCI_DCM_DEFAULT); /* describe the target table */ OCI_DirPathSetColumn(dp, 1, "VAL_INT", SIZE_COL1, NULL); OCI_DirPathSetColumn(dp, 2, "VAL_STR", SIZE_COL2, NULL); OCI_DirPathSetColumn(dp, 3, "VAL_DATE", SIZE_COL3, "YYYYMMDD"); /* prepare the load */ OCI_DirPathPrepare(dp); /* perform the load - NB_LOAD iterations of SIZE_ARRAY rows */ nb_rows = OCI_DirPathGetMaxRows(dp); for (i = 0; i < NB_LOAD; i++) { /* reset the load at each iteration */ OCI_DirPathReset(dp); /* set the values for the current load iteration */ for (j = 1; j <= nb_rows; j++) { /* conversion and loading errors are performed on the first load for rows 5 and 8 */ if (i == 0 && (j == 5 || j == 8) && gen_conv_error) { /* generate a conversion error - not null clause violation on column val_int */ OCI_DirPathSetEntry(dp, j, 1, NULL, 0, TRUE); OCI_DirPathSetEntry(dp, j, 2, NULL, 0, TRUE); OCI_DirPathSetEntry(dp, j, 3, NULL, 0, TRUE); } else if (i == 0 && (j == 5 || j == 8) && gen_load_error) { /* generate a load error - if partitioning available, insert value out of declared partitions ranges */ sprintf(val1, "%04d", 2500); sprintf(val2, "value %05d", j + (i*SIZE_ARRAY)); sprintf(val3, "%04d%02d%02d", (j % 23) + 1 + 2000, (j % 11) + 1, (j % 23) + 1); OCI_DirPathSetEntry(dp, j, 1, val1, (unsigned int)strlen(val1), TRUE); OCI_DirPathSetEntry(dp, j, 2, val2, (unsigned int)strlen(val2), TRUE); OCI_DirPathSetEntry(dp, j, 3, val3, (unsigned int)strlen(val3), TRUE); } else { /* default loading */ sprintf(val1, "%04d", j + (i*SIZE_ARRAY)); sprintf(val2, "value %05d", j + (i*SIZE_ARRAY)); sprintf(val3, "%04d%02d%02d", (j % 23) + 1 + 2000, (j % 11) + 1, (j % 23) + 1); OCI_DirPathSetEntry(dp, j, 1, val1, (unsigned int)strlen(val1), TRUE); OCI_DirPathSetEntry(dp, j, 2, val2, (unsigned int)strlen(val2), TRUE); OCI_DirPathSetEntry(dp, j, 3, val3, (unsigned int)strlen(val3), TRUE); } } /* load data to the server */ while (TRUE) { int nb_conv = 0; int nb_error = 0; /* convert data*/ int state = OCI_DirPathConvert(dp); /* retrieve the number of converted rows */ nb_conv += OCI_DirPathGetAffectedRows(dp); /* conversion or loading errors are performed on the first load */ if (i == 0) { if (gen_conv_error && !force && state == OCI_DPR_ERROR) { /* on conversion error in default mode, correct values for next conversion */ int row = OCI_DirPathGetErrorRow(dp); sprintf(val1, "%04d", row); sprintf(val2, "value %05d", row); sprintf(val3, "%04d%02d%02d", (row % 23) + 1 + 2000, (row % 11) + 1, (row % 23) + 1); OCI_DirPathSetEntry(dp, row, 1, val1, (unsigned int)strlen(val1), TRUE); OCI_DirPathSetEntry(dp, row, 2, val2, (unsigned int)strlen(val2), TRUE); OCI_DirPathSetEntry(dp, row, 3, val3, (unsigned int)strlen(val3), TRUE); nb_conv = 0; } if (gen_conv_error && force && state == OCI_DPR_COMPLETE) { /* on conversion error in force mode, check we got the expected errors*/ int err_row = OCI_DirPathGetErrorRow(dp); int err_col = OCI_DirPathGetErrorColumn(dp); while (err_row != 0) { check_results(con, dp, nb_error == 0 ? 5 : 8, err_row, "erred converted row index (force mode)"); check_results(con, dp, err_col, 1, "erred column index in force mode"); err_row = OCI_DirPathGetErrorRow(dp); err_col = OCI_DirPathGetErrorColumn(dp); nb_error++; } check_results(con, dp, NB_ERROR, nb_error, "conversion errors in force mode"); } } if (state == OCI_DPR_FULL) { /* buffer is too small - load the stream */ state = OCI_DirPathLoad(dp); /* as the stream cannot accept all rows in one go, we need to do conversion+load until all rows are processed */ while (nb_conv < SIZE_ARRAY) { for (j = 1; j <= nb_rows - nb_conv; j++) { sprintf(val1, "%04d", (j + nb_conv) + (i*SIZE_ARRAY)); sprintf(val2, "value %05d", (j + nb_conv) + (i*SIZE_ARRAY)); sprintf(val3, "%04d%02d%02d", ((j + nb_conv) % 23) + 1 + 2000, ((j + nb_conv) % 11) + 1, ((j + nb_conv) % 23) + 1); OCI_DirPathSetEntry(dp, j, 1, val1, (unsigned int)strlen(val1), TRUE); OCI_DirPathSetEntry(dp, j, 2, val2, (unsigned int)strlen(val2), TRUE); OCI_DirPathSetEntry(dp, j, 3, val3, (unsigned int)strlen(val3), TRUE); } /* convert again */ state = OCI_DirPathConvert(dp); nb_conv = OCI_DirPathGetAffectedRows(dp); /* load again */ state = OCI_DirPathLoad(dp); } break; } else if (state == OCI_DPR_COMPLETE) { /* conversion is complete */ check_results(con, dp, (gen_conv_error && i == 0 && force) ? (SIZE_ARRAY - NB_ERROR) : SIZE_ARRAY, nb_conv, "converted rows"); state = OCI_DirPathLoad(dp); if (gen_load_error && i == 0) { /* on loading error in force mode, check we got the expected errors*/ int err_row = OCI_DirPathGetErrorRow(dp); while (err_row != 0) { check_results(con, dp, nb_error == 0 ? 5 : 8, err_row, "erred loaded row index"); err_row = OCI_DirPathGetErrorRow(dp); nb_error++; } check_results(con, dp, NB_ERROR, nb_error, "loading errors in force mode"); } check_results(con, dp, (gen_load_error && i == 0) ? nb_conv - NB_ERROR : nb_conv, OCI_DirPathGetAffectedRows(dp), "loaded rows"); break; } } } /* commit load */ OCI_DirPathFinish(dp); /* verify loading results */ check_results(con, dp, ((gen_conv_error && force) || gen_load_error) ? (NB_TOTAL - NB_ERROR) : NB_TOTAL, OCI_DirPathGetRowCount(dp), "total loaded rows"); /* check data integrity in database */ check_data(con, dp, gen_conv_error, gen_load_error, force); /* free direct path*/ OCI_DirPathFree(dp); /* drop table */ drop_table(con); printf("SUCCESS\n"); }
static int test(int argc, char **argv, int over4k) { LOGINREC *login; int i; DBINT testint; FILE *fp; long result, isiz; char *blob, *rblob; DBBINARY *textPtr = NULL, *timeStamp = NULL; char objname[256]; char rbuf[BLOB_BLOCK_SIZE]; long numread; int data_ok; int numtowrite, numwritten; set_malloc_options(); read_login_info(argc, argv); fprintf(stdout, "Starting %s\n", argv[0]); dbinit(); dberrhandle(syb_err_handler); dbmsghandle(syb_msg_handler); fprintf(stdout, "About to logon\n"); login = dblogin(); DBSETLPWD(login, PASSWORD); DBSETLUSER(login, USER); DBSETLAPP(login, "t0013"); fprintf(stdout, "About to open, PASSWORD: %s, USER: %s, SERVER: %s\n", "", "", ""); /* PASSWORD, USER, SERVER); */ dbproc = dbopen(login, SERVER); dbprocw = dbopen(login, SERVER); if (strlen(DATABASE)) { dbuse(dbproc, DATABASE); dbuse(dbprocw, DATABASE); } dbloginfree(login); fprintf(stdout, "logged in\n"); if (argc == 1) { argv = testargs; argc = 3; } if (argc < 3) { fprintf(stderr, "Usage: %s infile outfile\n", argv[0]); return 1; } if ((fp = fopen(argv[1], "rb")) == NULL) { fprintf(stderr, "Cannot open input file: %s\n", argv[1]); return 2; } fprintf(stdout, "Reading binary input file\n"); fseek(fp, 0, SEEK_END); isiz = ftell(fp); fseek(fp, 0, SEEK_SET); blob = malloc(isiz); assert(blob); result = fread((void *) blob, isiz, 1, fp); assert(result == 1); fclose(fp); drop_table(); sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } sql_cmd(dbproc); dbsqlexec(dbproc); while (dbresults(dbproc) != NO_MORE_RESULTS) { /* nop */ } sql_cmd(dbproc); dbsqlexec(dbproc); if (dbresults(dbproc) != SUCCEED) { fprintf(stderr, "Error inserting blob\n"); return 4; } for (i=0; (result = dbnextrow(dbproc)) != NO_MORE_ROWS; i++) { assert(REG_ROW == result); printf("fetching row %d\n", i+1); strcpy(objname, TABLE_NAME ".PigTure"); textPtr = dbtxptr(dbproc, 1); timeStamp = dbtxtimestamp(dbproc, 1); break; /* can't proceed until no more rows */ } assert(REG_ROW == result || 0 < i); if (!textPtr && !timeStamp && dbtds(dbproc) >= DBTDS_7_2) { printf("Protocol 7.2+ detected, test not supported\n"); free(blob); dbclose(dbproc); dbproc = NULL; dbexit(); exit(0); } if (!textPtr) { fprintf(stderr, "Error getting textPtr\n"); exit(1); } /* * Use #ifdef if you want to test dbmoretext mode (needed for 16-bit apps) * Use #ifndef for big buffer version (32-bit) */ fprintf(stdout, "writing text ... "); if (over4k) { if (dbwritetext(dbprocw, objname, textPtr, DBTXPLEN, timeStamp, FALSE, isiz, (BYTE*) blob) != SUCCEED) return 5; fprintf(stdout, "done (in one shot)\n"); for (; (result = dbnextrow(dbproc)) != NO_MORE_ROWS; i++) { assert(REG_ROW == result); printf("fetching row %d?\n", i+1); } } else { if (dbwritetext(dbprocw, objname, textPtr, DBTXPLEN, timeStamp, FALSE, isiz, NULL) != SUCCEED) return 15; fprintf(stdout, "done\n"); fprintf(stdout, "dbsqlok\n"); dbsqlok(dbprocw); fprintf(stdout, "dbresults\n"); dbresults(dbprocw); numtowrite = 0; /* Send the update value in chunks. */ for (numwritten = 0; numwritten < isiz; numwritten += numtowrite) { fprintf(stdout, "dbmoretext %d\n", 1 + numwritten); numtowrite = (isiz - numwritten); if (numtowrite > BLOB_BLOCK_SIZE) numtowrite = BLOB_BLOCK_SIZE; dbmoretext(dbprocw, (DBINT) numtowrite, (BYTE *) (blob + numwritten)); } dbsqlok(dbprocw); while (dbresults(dbprocw) != NO_MORE_RESULTS){ printf("suprise!\n"); } } #if 0 if (SUCCEED != dbclose(dbproc)){ fprintf(stdout, "dbclose failed"); exit(1); } dbproc = dbopen(login, SERVER); assert(dbproc); if (strlen(DATABASE)) { dbuse(dbproc, DATABASE); } #endif sql_cmd(dbproc); dbsqlexec(dbproc); if (dbresults(dbproc) != SUCCEED) { failed = 1; fprintf(stdout, "Was expecting a result set."); exit(1); } for (i = 1; i <= dbnumcols(dbproc); i++) { printf("col %d, \"%s\", is type %s\n", i, dbcolname(dbproc, i), dbprtype(dbcoltype(dbproc, i))); } if (2 != dbnumcols(dbproc)) { fprintf(stderr, "Failed. Expected 2 columns\n"); exit(1); } if (SUCCEED != dbbind(dbproc, 1, INTBIND, -1, (BYTE *) & testint)) { fprintf(stderr, "Had problem with bind\n"); exit(1); } if (REG_ROW != dbnextrow(dbproc)) { fprintf(stderr, "Failed. Expected a row\n"); exit(1); } if (testint != 1) { failed = 1; fprintf(stderr, "Failed. Expected i to be %d, was %d\n", 1, (int) testint); exit(1); } dbnextrow(dbproc); /* get the image */ sql_cmd(dbproc); dbsqlexec(dbproc); dbresults(dbproc); fprintf(stdout, "select 2\n"); sql_cmd(dbproc); dbsqlexec(dbproc); if (dbresults(dbproc) != SUCCEED) { fprintf(stderr, "Error extracting blob\n"); return 6; } numread = 0; rblob = NULL; while ((result = dbreadtext(dbproc, rbuf, BLOB_BLOCK_SIZE)) != NO_MORE_ROWS) { if (result != 0) { /* this indicates not end of row */ rblob = (char*) realloc(rblob, result + numread); memcpy((void *) (rblob + numread), (void *) rbuf, result); numread += result; } } data_ok = 1; if (memcmp(blob, rblob, numread) != 0) { printf("Saving first blob data row to file: %s\n", argv[2]); if ((fp = fopen(argv[2], "wb")) == NULL) { fprintf(stderr, "Unable to open output file: %s\n", argv[2]); return 3; } fwrite((void *) rblob, numread, 1, fp); fclose(fp); failed = 1; data_ok = 0; } printf("Read blob data row %d --> %s %ld byte comparison\n", (int) testint, data_ok ? "PASSED" : "failed", numread); free(rblob); if (dbnextrow(dbproc) != NO_MORE_ROWS) { failed = 1; fprintf(stderr, "Was expecting no more rows\n"); exit(1); } free(blob); drop_table(); dbclose(dbproc); dbproc = NULL; dbexit(); return 0; }
int main(int argc, char** argv) { if (argc != 3) { std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; exit(-1); } char * mysqld_sock = argv[1]; const char *connectstring = argv[2]; ndb_init(); MYSQL mysql; /************************************************************** * Connect to mysql server and create table * **************************************************************/ { if ( !mysql_init(&mysql) ) { std::cout << "mysql_init failed\n"; exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", 0, mysqld_sock, 0) ) MYSQLERROR(mysql); mysql_query(&mysql, "CREATE DATABASE ndb_examples"); if (mysql_query(&mysql, "USE ndb_examples") != 0) MYSQLERROR(mysql); create_table(mysql); } /************************************************************** * Connect to ndb cluster * **************************************************************/ Ndb_cluster_connection cluster_connection(connectstring); if (cluster_connection.connect(4, 5, 1)) { std::cout << "Unable to connect to cluster within 30 secs." << std::endl; exit(-1); } // Optionally connect and wait for the storage nodes (ndbd's) if (cluster_connection.wait_until_ready(30,0) < 0) { std::cout << "Cluster was not ready within 30 secs.\n"; exit(-1); } Ndb myNdb(&cluster_connection,"ndb_examples"); if (myNdb.init(1024) == -1) { // Set max 1024 parallel transactions APIERROR(myNdb.getNdbError()); exit(-1); } /******************************************* * Check table definition * *******************************************/ int column_color; { const NdbDictionary::Dictionary* myDict= myNdb.getDictionary(); const NdbDictionary::Table *t= myDict->getTable("api_scan"); if(t == NULL) { std::cout << "Dictionary::getTable() failed."; exit(-1); } Car car; if (t->getColumn("COLOR")->getLength() != sizeof(car.color) || t->getColumn("BRAND")->getLength() != sizeof(car.brand)) { std::cout << "Wrong table definition" << std::endl; exit(-1); } column_color= t->getColumn("COLOR")->getColumnNo(); } if(populate(&myNdb) > 0) std::cout << "populate: Success!" << std::endl; if(scan_print(&myNdb) > 0) std::cout << "scan_print: Success!" << std::endl << std::endl; std::cout << "Going to delete all pink cars!" << std::endl; { /** * Note! color needs to be of exact the same size as column defined */ Car tmp; sprintf(tmp.color, "Pink"); if(scan_delete(&myNdb, column_color, tmp.color) > 0) std::cout << "scan_delete: Success!" << std::endl << std::endl; } if(scan_print(&myNdb) > 0) std::cout << "scan_print: Success!" << std::endl << std::endl; { /** * Note! color1 & 2 need to be of exact the same size as column defined */ Car tmp1, tmp2; sprintf(tmp1.color, "Blue"); sprintf(tmp2.color, "Black"); std::cout << "Going to update all " << tmp1.color << " cars to " << tmp2.color << " cars!" << std::endl; if(scan_update(&myNdb, column_color, tmp1.color, tmp2.color) > 0) std::cout << "scan_update: Success!" << std::endl << std::endl; } if(scan_print(&myNdb) > 0) std::cout << "scan_print: Success!" << std::endl << std::endl; /** * Drop table */ drop_table(mysql); return 0; }
int main(int argc, char** argv) { if (argc != 3) { std::cout << "Arguments are <socket mysqld> <connect_string cluster>.\n"; exit(-1); } char * mysqld_sock = argv[1]; const char *connectstring = argv[2]; ndb_init(); Ndb_cluster_connection *cluster_connection= new Ndb_cluster_connection(connectstring); // Object representing the cluster int r= cluster_connection->connect(5 /* retries */, 3 /* delay between retries */, 1 /* verbose */); if (r > 0) { std::cout << "Cluster connect failed, possibly resolved with more retries.\n"; exit(-1); } else if (r < 0) { std::cout << "Cluster connect failed.\n"; exit(-1); } if (cluster_connection->wait_until_ready(30,0) < 0) { std::cout << "Cluster was not ready within 30 secs." << std::endl; exit(-1); } // connect to mysql server MYSQL mysql; if ( !mysql_init(&mysql) ) { std::cout << "mysql_init failed\n"; exit(-1); } if ( !mysql_real_connect(&mysql, "localhost", "root", "", "", 0, mysqld_sock, 0) ) MYSQLERROR(mysql); /******************************************** * 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); Ndb* myNdb = new Ndb( cluster_connection, "TEST_DB_1" ); // Object representing the database NdbTransaction* myNdbTransaction[2]; // For transactions NdbOperation* myNdbOperation; // For operations if (myNdb->init(2) == -1) { // Want two parallel insert transactions APIERROR(myNdb->getNdbError()); exit(-1); } /****************************************************** * Insert (we do two insert transactions in parallel) * ******************************************************/ const NdbDictionary::Dictionary* myDict= myNdb->getDictionary(); const NdbDictionary::Table *myTable= myDict->getTable("MYTABLENAME"); if (myTable == NULL) APIERROR(myDict->getNdbError()); for (int i = 0; i < 2; i++) { myNdbTransaction[i] = myNdb->startTransaction(); if (myNdbTransaction[i] == NULL) APIERROR(myNdb->getNdbError()); myNdbOperation = myNdbTransaction[i]->getNdbOperation(myTable); if (myNdbOperation == NULL) APIERROR(myNdbTransaction[i]->getNdbError()); myNdbOperation->insertTuple(); myNdbOperation->equal("ATTR1", 20 + i); myNdbOperation->setValue("ATTR2", 20 + i); // Prepare transaction (the transaction is NOT yet sent to NDB) myNdbTransaction[i]->executeAsynchPrepare(NdbTransaction::Commit, &callback, NULL); } // Send all transactions to NDB myNdb->sendPreparedTransactions(0); // Poll all transactions myNdb->pollNdb(3000, 2); // Close all transactions for (int i = 0; i < 2; i++) myNdb->closeTransaction(myNdbTransaction[i]); delete myNdb; delete cluster_connection; drop_table(mysql); ndb_end(0); return 0; }
int main(int argc, char* argv[]) { ib_err_t err; ib_crsr_t crsr; ib_trx_t ib_trx; (void)argc; (void)argv; err = ib_init(); assert(err == DB_SUCCESS); test_configure(); err = ib_startup("barracuda"); assert(err == DB_SUCCESS); err = create_database(DATABASE); assert(err == DB_SUCCESS); printf("Create table\n"); err = create_table(DATABASE, TABLE); assert(err == DB_SUCCESS); printf("Begin transaction\n"); ib_trx = ib_trx_begin(IB_TRX_REPEATABLE_READ); assert(ib_trx != NULL); printf("Open cursor\n"); err = open_table(DATABASE, TABLE, ib_trx, &crsr); assert(err == DB_SUCCESS); printf("Lock table in IX\n"); err = ib_cursor_lock(crsr, IB_LOCK_IX); assert(err == DB_SUCCESS); printf("Insert rows\n"); err = insert_rows(crsr); assert(err == DB_SUCCESS); printf("Query table\n"); err = do_query(crsr); assert(err == DB_SUCCESS); printf("Close cursor\n"); err = ib_cursor_close(crsr); assert(err == DB_SUCCESS); crsr = NULL; printf("Commit transaction\n"); err = ib_trx_commit(ib_trx); assert(err == DB_SUCCESS); printf("Drop table\n"); err = drop_table(DATABASE, TABLE); assert(err == DB_SUCCESS); err = ib_shutdown(IB_SHUTDOWN_NORMAL); assert(err == DB_SUCCESS); #ifdef UNIV_DEBUG_VALGRIND VALGRIND_DO_LEAK_CHECK; #endif return(EXIT_SUCCESS); }