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"); }
int main(int argc, char **argv) { sqlite3 *db; sqlite3_open("test.db", &db); sqlite3_create_function( db, "hello_newman", 1, SQLITE_UTF8, NULL, hello_newman, NULL, NULL); /* Log SQL as it is executed. */ log_sql(db,1); /* Call function with one text argument. */ fprintf(stdout, "Calling with one argument.\n"); print_sql_result(db, "select hello_newman('Jerry')"); /* Call function with two arguments. This will fail as we registered the ** function as taking only one argument. */ fprintf(stdout, "\nCalling with two arguments.\n"); print_sql_result(db, "select hello_newman ('Jerry', 'Elaine')"); /* Call function with no arguments. This will fail too */ fprintf(stdout, "\nCalling with no arguments.\n"); print_sql_result(db, "select hello_newman()"); /* Done */ sqlite3_close(db); return 0; }
int main(int argc, char **argv) { int rc; sqlite3 *db; const char* sql; sqlite3_open("test.db", &db); sqlite3_create_function( db, "function", -1, SQLITE_UTF8, NULL, function, NULL, NULL); /* Turn on SQL logging */ log_sql(db, 1); /* Call function with one text argument. */ execute(db, "select function(1)"); /* Call function with several arguments of various types. */ execute(db, "select function(1, 2.71828)"); /* Call function with variable arguments, the first argument’s value ** being 'fail'. This will trigger the function to call ** sqlite3_result_error(). */ execute(db, "select function('fail', 1, 2.71828, 'three', X'0004', NULL)"); /* Done */ sqlite3_close(db); return 0; }
int main(int argc, char **argv) { int rc; sqlite3 *db; char *sql; rc = sqlite3_open("test.db", &db); if(rc) { fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db)); return 1; } setup(db); /* I. Register SQL functions ---------------------------------------------*/ /* Generates and installs validation triggers. */ rc = sqlite3_create_function( db, "add_strict_type_check", 2, SQLITE_UTF8, db, add_strict_type_check_udf, NULL, NULL); /* Removes validation triggers. */ sqlite3_create_function( db, "drop_strict_type_check", 2, SQLITE_UTF8, db, drop_strict_type_check_udf, NULL, NULL); /* Convenience function for pulling a column's type from sqlite_master. It * is a fine-grained 'PRAGMA table_info()'.*/ sqlite3_create_function( db, "column_type", 2, SQLITE_UTF8, db, column_type_udf, NULL, NULL); /* Type Validation: Called to validate integer. */ sqlite3_create_function( db, "validate_int", 1, SQLITE_UTF8, db, validate_int_udf, NULL, NULL); /* Type Validation: Called to validate long integer. Same UDF as above, * different SQL function name. */ sqlite3_create_function( db, "validate_long", 1, SQLITE_UTF8, db, validate_int_udf, NULL, NULL); /* Type Validation: Called to validate float. */ sqlite3_create_function( db, "validate_double", 1, SQLITE_UTF8, db, validate_double_udf, NULL, NULL); /* Type Validation: Called to validate long integer. Same UDF as above, * different SQL function name. */ sqlite3_create_function( db, "validate_float", 1, SQLITE_UTF8, db, validate_double_udf, NULL, NULL); /* II. Test ---------------------------------------------------------------*/ log_sql(db,1); /* Add type check constraint trigger for types.id */ printf("1. Add strict typing:\n"); execute(db, "select add_strict_type_check('types', '*')"); printf("\n"); /* Insert a record with valid id */ printf("2. Insert integer value -- should succeed:\n"); execute(db, "insert into types (x) values (1)"); printf("\n"); /* Insert a record with invalid id type*/ printf("3. Update with invalid values -- should fail:\n"); execute(db, "update types set x = 'abc'"); execute(db, "update types set y = 'abc'"); printf("\n"); /* Remove type check constraint trigger for types.id */ printf("4. Remove strict typing\n"); execute(db, "select drop_strict_type_check('types', '*')"); printf("\n"); /* Insert a record with invalid id type*/ printf("5. Update with non-integer value -- should succeed:\n"); execute(db, "update types set x = 'not an int'"); printf("\n"); printf("6. Select records:\n"); print_sql_result(db, "select * from types"); printf("\n"); /* Test column_type() */ printf("7. Test column_type() UDF\n"); sql = "select column_type('types', 'id') as 'id',\n" " column_type('types', 'x') as 'x',\n" " column_type('types', 'y') as 'y'"; print_sql_result(db, sql); printf("\n"); sqlite3_close(db); return 0; }
int main( int argc, char *argv[]) { Arb_connection *dbinit; /* only used on call to module_std_init */ ACCOUNTS *Account_list; char *env_arbordata; char *env_ctrl_rpt_fname; int rc; #define HIGH_DB_DEBUG 4 /* Remember to turn off * OAM_ENV_MA_CONN */ module_std_init(argc, argv,BLSMODULE, FALSE, &iserver_id, &env_arbordata, &env_ctrl_rpt_fname, &Trace_on, &Timer_on, &dbinit); arb_close(dbinit,TRUE); if (Trace_on & HIGH_DB_DEBUG) arb_set_db_debug_level(HIGH_DEBUG); /* HIGH_DEBUG #defined in arbor_global.h */ oam_register_new_reaction( sql_doreact); if (arborm_login_to_default(ARB_STD_CONNECT,&dbfetch) == FAILURE) { emit(BIPMOD,BIP_DB_OPEN_FAIL,"dbfetch"); return(EXIT_FAILURE); } /* * Server_id is a two digit string less than 64. * Process_num is a one digit string consisting of the digit char that * follows "bip0" in the process_id. */ sprintf(Server_id,"%d",iserver_id & 0x3f); strncpy(Process_num,arb_get_process_id()+4,1); Process_num[1] = '\0'; /* * CAMqa56390 : Check for valid value for process number. */ if (Process_num[0] < '0' || Process_num[0] > '9') { emit(BLSMOD, BLS_STARTUP_FAIL, arb_get_process_id()); return(EXIT_FAILURE); } if (env_arbordata) strcpy(arbordata, env_arbordata); if (env_ctrl_rpt_fname) strcpy(Ctrl_rpt_fname, env_ctrl_rpt_fname); if (arborm_login_to_admin(ARB_STD_CONNECT,&dbadmin) == FAILURE) { emit(BLSMOD,BLS_DB_OPEN_FAIL,"dbadmin"); return(EXIT_FAILURE); } /** Load up BIP's error messages. ** We need to do so, because we will be calling functions in ** bip_work_list.c which emits BIP module messages when error ** occurs. **/ rc = emit_load_module_messages( dbadmin, "BIP"); if( rc == 0) { emit( BLSMOD, BLS_NO_BIP_MSSGS); return EXIT_FAILURE; } Proc_mode = atoi( argv[ARGV_TASKMODE_POS]); Proc_mode -= BIP_TO_BIC_TASKMODE_SHIFT_VALUE; /* arbor_config.h */ obtain_sql_query( argc, argv); log_sql(sql_query); TRACE(); rc = get_account_ids( (char*) sql_query); /* bip_work_list.c module */ if( rc == Failure) { TRACE(); emit(BLSMOD, BLS_GET_IDS_FAIL); } else { TRACE(); Account_list = grab_accounts_from_bip_module(); send_accounts_to_bic( Account_list); free_grabbed_accounts( Account_list); (void)arb_cancel(dbfetch); arb_close(dbfetch,TRUE); arb_close(dbadmin,TRUE); } inform_bic_of_query_finish( argv[ARGV_PROCNAME_POS], iserver_id); fflush(stdout); fflush(stderr); module_std_terminate(NULL); return(EXIT_SUCCESS); }