int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->read_env();
    Test->print_env();

    printf("Connecting to RWSplit %s\n", Test->maxscale_IP);
    Test->connect_rwsplit();

    printf("Setup firewall to block mysql on master\n"); fflush(stdout);
    Test->repl->block_node(0);

    printf("Trying query to RWSplit, expecting failure, but not a crash\n"); fflush(stdout);
    execute_query(Test->conn_rwsplit, (char *) "show processlist;");

    printf("Setup firewall back to allow mysql\n"); fflush(stdout);
    Test->repl->unblock_node(0);

    sleep(10);

    global_result += check_maxscale_alive();

    Test->close_rwsplit();


    printf("Reconnecting and trying query to RWSplit\n"); fflush(stdout);
    Test->connect_rwsplit();
    global_result += execute_query(Test->conn_rwsplit, (char *) "show processlist;");
    Test->close_rwsplit();

    Test->copy_all_logs(); return(global_result);
}
Example #2
0
void tail(){
    switch(opts.cmd) {

        case FOLLOW:
            while(TRUE) {
                if (opts._last_row_id >= 0) {
                    execute_query("SELECT " SELECT_FIELDS " from fwevents WHERE id > ? ORDER BY ID ASC", opts._last_row_id , print_row);
                } else {
                    execute_query("SELECT * FROM (SELECT " SELECT_FIELDS " from fwevents ORDER BY ID DESC LIMIT ?) ORDER BY ID ASC", opts.c_recs , print_row);
                }
                Sleep(opts.sleep);
            }
            break;

        case LAST_N:
            execute_query("SELECT * FROM (SELECT " SELECT_FIELDS " from fwevents ORDER BY ID DESC LIMIT ?) ORDER BY ID ASC", opts.c_recs , print_row);
            break;

        case ALL:
            execute_query("SELECT " SELECT_FIELDS " from fwevents ORDER BY ID ASC", 0 , print_row);
            break;

        default:       // Should never get here, but if we do then just exit
            error("Bug found! Internal command received: %d. Please notify the author about this.", opts.cmd);
    }
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->read_env();
    Test->print_env();

    Test->connect_maxscale();

    printf("Trying SELECT @a:=@a+1 as a, test.b FROM test\n"); fflush(stdout);
    global_result += execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS test; CREATE TABLE test (b integer);");
    for (int i=0; i<10000;i++) {execute_query(Test->conn_rwsplit, "insert into test value(2);");}
    if (execute_query(Test->conn_rwsplit, "SELECT @a:=@a+1 as a, test.b FROM test;") == 0) {
        printf("Query succeded, but expected to fail. Test FAILED!\n"); fflush(stdout);
        global_result++;
    }
    printf("Trying USE test\n"); fflush(stdout);
    global_result += execute_query(Test->conn_rwsplit, "USE test");

    global_result += execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS test;");

    printf("Checking if MaxScale alive\n"); fflush(stdout);
    Test->close_maxscale_connections();

    printf("Checking logs\n"); fflush(stdout);
    global_result    += check_log_err((char *) "Warning : The query can't be routed to all backend servers because it includes SELECT and SQL variable modifications which is not supported", TRUE);
    global_result    += check_log_err((char *) "SELECT with session data modification is not supported if configuration parameter use_sql_variables_in=all", TRUE);

    global_result += check_maxscale_alive();

    Test->copy_all_logs(); return(global_result);
}
Example #4
0
void MetadataStorage::create_tables() {
    const char* query = nullptr;

    // Create volumes table
    query =
            "CREATE TABLE IF NOT EXISTS akumuli_volumes("
            "id INTEGER UNIQUE,"
            "path TEXT UNIQUE"
            ");";
    execute_query(query);

    // Create configuration table (key-value-commmentary)
    query =
            "CREATE TABLE IF NOT EXISTS akumuli_configuration("
            "name TEXT UNIQUE,"
            "value TEXT,"
            "comment TEXT"
            ");";
    execute_query(query);

    query =
            "CREATE TABLE IF NOT EXISTS akumuli_series("
            "id INTEGER PRIMARY KEY UNIQUE,"
            "series_id TEXT,"
            "keyslist TEXT,"
            "storage_id INTEGER UNIQUE"
            ");";
    execute_query(query);
}
Example #5
0
int connect_db(char *db_name)
{
	int chk;

	rc = sqlite3_open(db_name, &db);
	if(rc)
	{
		fprintf(stderr, "Can't open database : %s\n", sqlite3_errmsg(db));
		sqlite3_close(db);
		
		return -1;
	}
	
	chk = execute_query("create table if not exists AP (ap_essid char(256), ap_bssid char(17) primary key, ap_channel int)", 0, 0);
	if(chk == -1)
	{
		puts("create table \"AP\" error");

		return -1;
	}

	chk = execute_query("create table if not exists client (conn_ap_bssid char(17), client_bssid char(17) primary key)", 0, 0);
	if(chk == -1)
	{
		puts("create table \"client\" error");

		return -1;
	}

	return 0;
}
int main(int argc, char *argv[])
{
  MYSQL *conn_rwsplit;

  int i;
  int global_result = 0;

  char ip[15];
  char maxscaleIP[15];
  char ip1[15];

  int IP_end;
  int NodesNum;

  if (argc != 3) { printf("Usage: ./rw_select_insert Last_digits_of_IP number_of_VM\n"); exit(2); }

  sscanf(argv[1], "%d", &IP_end);
  if ( (IP_end < 0) || (IP_end > 255) ) { printf("Wrong last digits of IP\n"); exit(2); }
  sprintf(ip, "192.168.122.%d", IP_end);
  sprintf(maxscaleIP, "192.168.122.%s", getenv("maxscaleIP"));
  
  sscanf(argv[2], "%d", &NodesNum);
  if ( (NodesNum < 3) || (NodesNum > 255) ) { printf("Wrong number of nodes\n"); exit(2); }
   NodesNum--;

  tolerance=0;
  // Connecting to all nodes
  if (connect_all_nodes(nodes, IP_end, NodesNum) != 0) {exit(2);}

  // connect to the MaxScale server (rwsplit)
  conn_rwsplit = open_conn(4006, maxscaleIP);
  if (conn_rwsplit == NULL ) {
    printf("Can't connect to MaxScale\n");
    exit(1);
  } else {
 
    global_result += execute_query(conn_rwsplit, "DROP TABLE IF EXISTS t1;");
    global_result += execute_query(conn_rwsplit, "create table t1 (x1 int);");


    get_global_status_allnodes(&selects[0], &inserts[0], nodes, NodesNum, silent);
    global_result += execute_query(conn_rwsplit, "select * from t1;"); 
    get_global_status_allnodes(&new_selects[0], &new_inserts[0], nodes, NodesNum, silent);
    print_delta(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], NodesNum);


    global_result += execute_query(conn_rwsplit, "insert into t1 values(1);"); 
    get_global_status_allnodes(&new_selects[0], &new_inserts[0], nodes, NodesNum, silent);
    print_delta(&new_selects[0], &new_inserts[0], &selects[0], &inserts[0], NodesNum); 

  // close connections
    mysql_close(conn_rwsplit);
  }
  for (i=0; i<NodesNum; i++) { mysql_close(nodes[i]); }

  exit(global_result);
}
int main(int argc, char *argv[])
{
    pthread_t parall_traffic1[100];
    int check_iret[100];

    Test = new TestConnections(argc, argv);
    int global_result = 0;

    Test->read_env();
    Test->print_env();

    printf("Connecting to RWSplit %s\n", Test->maxscale_IP);
    Test->connect_rwsplit();

    global_result += create_t1(Test->conn_rwsplit);
    create_insert_string(sql, 65000, 1);


    for (int j = 0; j < 25; j++) {
        check_iret[j] = pthread_create( &parall_traffic1[j], NULL, parall_traffic, NULL);
    }

    sleep(1);

    printf("Setup firewall to block mysql on master\n"); fflush(stdout);
    Test->repl->block_node(0); fflush(stdout);

    sleep(1);

    printf("Trying query to RWSplit, expecting failure, but not a crash\n"); fflush(stdout);
    execute_query(Test->conn_rwsplit, (char *) "show processlist;");fflush(stdout);

    sleep(1);

    printf("Setup firewall back to allow mysql\n"); fflush(stdout);
    Test->repl->unblock_node(0); fflush(stdout);
    sleep(10);
    exit_flag = 1;
    sleep(10);

    printf("Checking Maxscale is alive\n"); fflush(stdout);
    global_result += check_maxscale_alive(); fflush(stdout);

    Test->close_rwsplit(); fflush(stdout);


    printf("Reconnecting and trying query to RWSplit\n"); fflush(stdout);
    Test->connect_rwsplit();
    global_result += execute_query(Test->conn_rwsplit, (char *) "show processlist;");
    Test->close_rwsplit();

    exit_flag = 1;
    sleep(10);

    Test->copy_all_logs(); return(global_result);
}
void insert_data(TestConnections& test, const char *table, const char* type, const char** values)
{
    test.repl->connect();
    execute_query(test.repl->nodes[0], "CREATE TABLE %s(%s %s)", table, field_name, type);

    for (int i = 0; values[i]; i++)
    {
        execute_query(test.repl->nodes[0], "INSERT INTO %s VALUES (%s)", table, values[i]);
    }

    execute_query(test.repl->nodes[0], "DROP TABLE %s", table);
    test.repl->close_connections();
}
int main(int argc, char *argv[])
{
    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(30);
    MYSQL * conn_found_rows;
    my_ulonglong rows;


    Test->repl->connect();
    Test->connect_maxscale();

    conn_found_rows = open_conn_db_flags(Test->rwsplit_port, Test->maxscale_IP, (char *) "test",
                                         Test->maxscale_user, Test->maxscale_password, CLIENT_FOUND_ROWS, Test->ssl);

    Test->set_timeout(30);
    execute_query(Test->conn_rwsplit, "DROP TABLE IF EXISTS t1");
    execute_query(Test->conn_rwsplit, "CREATE TABLE t1(id INT PRIMARY KEY, val INT, msg VARCHAR(100))");
    execute_query(Test->conn_rwsplit,
                  "INSERT INTO t1 VALUES (1, 1, 'foo'), (2, 1, 'bar'), (3, 2, 'baz'), (4, 2, 'abc')");

    Test->set_timeout(30);
    execute_query_affected_rows(Test->conn_rwsplit, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows);
    Test->tprintf("update #1: %ld (expeced value is 2)\n", (long) rows);
    if (rows != 2)
    {
        Test->add_result(1, "Affected rows is not 2\n");
    }

    Test->set_timeout(30);
    execute_query_affected_rows(Test->conn_rwsplit, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows);
    Test->tprintf("update #2: %ld  (expeced value is 0)\n", (long) rows);
    if (rows != 0)
    {
        Test->add_result(1, "Affected rows is not 0\n");
    }

    Test->set_timeout(30);
    execute_query_affected_rows(conn_found_rows, "UPDATE t1 SET msg='xyz' WHERE val=2", &rows);
    Test->tprintf("update #3: %ld  (expeced value is 2)\n", (long) rows);
    if (rows != 2)
    {
        Test->add_result(1, "Affected rows is not 2\n");
    }

    Test->close_maxscale_connections();

    int rval = Test->global_result;
    delete Test;
    return rval;

}
int start_transaction(TestConnections* Test)
{
    int local_result = 0;
    Test->tprintf("Transaction test\n");
    Test->tprintf("Start transaction\n");
    execute_query(Test->repl->nodes[0], (char *) "DELETE FROM t1 WHERE fl=10;");
    local_result += execute_query(Test->repl->nodes[0], (char *) "START TRANSACTION");
    local_result += execute_query(Test->repl->nodes[0], (char *) "SET autocommit = 0");
    Test->tprintf("INSERT data\n");
    local_result += execute_query(Test->repl->nodes[0], (char *) "INSERT INTO t1 VALUES(111, 10)");
    Test->stop_timeout();
    sleep(20);
    return local_result;
}
Example #11
0
int main(int argc, char* argv[]) {
  CassFuture* connect_future = NULL;
  CassCluster* cluster = cass_cluster_new();
  CassSession* session = cass_session_new();
  char* hosts = "127.0.0.1";
  if (argc > 1) {
    hosts = argv[1];
  }
  cass_cluster_set_contact_points(cluster, hosts);

  connect_future = cass_session_connect(session, cluster);

  if (cass_future_error_code(connect_future) == CASS_OK) {
    CassFuture* close_future = NULL;

    execute_query(session,
                  "CREATE KEYSPACE examples WITH replication = { \
                  'class': 'SimpleStrategy', 'replication_factor': '3' };");

    print_keyspace(session, "examples");

    execute_query(session,
                  "CREATE TABLE examples.schema_meta (key text, \
                  value bigint, \
                  PRIMARY KEY (key));");

    execute_query(session,
                  "CREATE FUNCTION examples.avg_state(state tuple<int, bigint>, val int) \
                  CALLED ON NULL INPUT RETURNS tuple<int, bigint> \
                  LANGUAGE java AS \
                    'if (val != null) { \
                      state.setInt(0, state.getInt(0) + 1); \
                      state.setLong(1, state.getLong(1) + val.intValue()); \
                    } \
Example #12
0
int main() 
{
    mysql_connect(); 

    list_drivers();
    list_data_sources();
    list_driver_information();
    list_tables();

    execute_query("select * from junk");
    execute_query("select count(*), sum(a) from junk");
    execute_query("select a, a+3, 3.141592654 from junk");
    execute_query("select j1.a, j2.a from junk j1 natural join junk j2");

    mysql_disconnect();
}
Example #13
0
/**
  \details Adds FMID and related URL in indexing database

  \param ictx valid pointer to indexing context
  \param username samAccountName for current user
  \param fmid FMID to record
  \param mapistore_URI mapistore URI string to associate with fmid

  \return MAPISTORE_SUCCESS on success,
	  MAPISTORE_ERR_EXIST if such entry already exists
	  MAPISTORE_ERR_NOT_INITIALIZED if ictx pointer is invalid (NULL)
	  MAPISTORE_ERR_INVALID_PARAMETER in case other parameters are not valid
	  MAPISTORE_ERR_DATABASE_OPS in case of MySQL error
 */
static enum mapistore_error mysql_record_add(struct indexing_context *ictx,
					   const char *username,
					   uint64_t fmid,
					   const char *mapistore_URI)
{
	int		ret;
	bool		IsSoftDeleted = false;
	char		*sql;
	TALLOC_CTX	*mem_ctx;

	/* Sanity checks */
	MAPISTORE_RETVAL_IF(!ictx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
	MAPISTORE_RETVAL_IF(!username, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
	MAPISTORE_RETVAL_IF(!fmid, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
	MAPISTORE_RETVAL_IF(!mapistore_URI, MAPISTORE_ERR_INVALID_PARAMETER, NULL);

	/* Check if the fid/mid doesn't already exist within the database */
	ret = mysql_search_existing_fmid(ictx, username, fmid, &IsSoftDeleted);
	MAPISTORE_RETVAL_IF(ret == MAPISTORE_SUCCESS, MAPISTORE_ERR_EXIST, NULL);

	mem_ctx = talloc_new(NULL);
	sql = talloc_asprintf(mem_ctx,
		"INSERT INTO %s "
		"(username, fmid, url, soft_deleted) "
		"VALUES ('%s', %"PRIu64", '%s', '%d')",
		INDEXING_TABLE, _sql(mem_ctx, username), fmid,
		_sql(mem_ctx, mapistore_URI), 0);

	ret = execute_query(MYSQL(ictx), sql);
	MAPISTORE_RETVAL_IF(ret != MYSQL_SUCCESS, MAPISTORE_ERR_DATABASE_OPS, mem_ctx);

	talloc_free(mem_ctx);
	return MAPISTORE_SUCCESS;
}
Example #14
0
/*
  execute - Execute a SQL statement

  This method executes the query specified as a character array. It copies
  the query to the local buffer then calls the execute_query() method to
  execute the query.

  If a result set is available after the query executes, the field
  packets and rows can be read separately using the get_field() and
  get_row() methods.

  query[in]       SQL statement (using normal memory access)
  progmem[in]     True if string is in program memory

  Returns boolean - True = a result set is available for reading
*/
boolean MySQL_Cursor::execute(const char *query, boolean progmem)
{
  int query_len;   // length of query

  if (progmem) {
    query_len = (int)strlen_P(query);
  } else {
    query_len = (int)strlen(query);
  }
  if (conn->buffer != NULL)
    free(conn->buffer);

  conn->buffer = (byte *)malloc(query_len+5);

  // Write query to packet
  if (progmem) {
    for (int c = 0; c < query_len; c++)
      conn->buffer[c+5] = pgm_read_byte_near(query+c);
  } else {
    memcpy(&conn->buffer[5], query, query_len);
  }

  // Send the query
  return execute_query(query_len);
}
Example #15
0
int main() {
  CassFuture* connect_future = NULL;
  CassCluster* cluster = cass_cluster_new();
  CassSession* session = cass_session_new();
  cass_cluster_set_contact_points(cluster, "127.0.0.1");

  connect_future = cass_session_connect(session, cluster);

  if (cass_future_error_code(connect_future) == CASS_OK) {
    CassFuture* close_future = NULL;

    execute_query(session,
                  "CREATE KEYSPACE examples WITH replication = { \
                  'class': 'SimpleStrategy', 'replication_factor': '3' };");

    print_keyspace(session, "examples");

    execute_query(session,
                  "CREATE TABLE examples.schema_meta (key text, \
                  value bigint, \
                  PRIMARY KEY (key));");

    print_table(session, "examples", "schema_meta");

    /* Close the session */
    close_future = cass_session_close(session);
    cass_future_wait(close_future);
    cass_future_free(close_future);
  } else {
int Mariadb_nodes::start_galera()
{
    char sys1[4096];
    int i;
    int global_result = 0;
    global_result += stop_nodes();

    printf("Starting new Galera cluster\n");  fflush(stdout);
    sprintf(&sys1[0], "ssh -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %s@%s '%s %s --wsrep-cluster-address=gcomm://'", sshkey[0], access_user, IP[0], access_sudo, start_db_command);
    printf("%s\n", sys1);  fflush(stdout);
    global_result +=  system(sys1); fflush(stdout);

    for (i = 1; i < N; i++) {
        printf("Starting node %d\n", i); fflush(stdout);
        sprintf(&sys1[0], "ssh -i %s -o StrictHostKeyChecking=no -o UserKnownHostsFile=/dev/null %s@%s '%s %s --wsrep-cluster-address=gcomm://%s'", sshkey[i], access_user, IP[i], access_sudo, start_db_command, IP_private[0]);
        printf("%s\n", sys1);  fflush(stdout);
        global_result += system(sys1); fflush(stdout);
    }
    sleep(5);

    global_result += connect();
    global_result += execute_query(nodes[0], create_repl_user);

    close_connections();
    return(global_result);
}
int main(int argc, char *argv[])
{

    TestConnections * Test = new TestConnections(argc, argv);
    Test->set_timeout(3000);
    int options_set = 3;
    if (Test->smoke)
    {
        options_set = 1;
    }

    Test->repl->connect();
    execute_query(Test->repl->nodes[0], (char *) "DROP TABLE IF EXISTS t1;");
    Test->repl->close_connections();
    sleep(5);

    for (int option = 0; option < options_set; option++)
    {
        Test->binlog_cmd_option = option;
        Test->start_binlog();
        test_binlog(Test);
    }

    Test->check_log_err("SET NAMES utf8mb4", false);
    Test->check_log_err("set autocommit=1", false);
    Test->check_log_err("select USER()", false);

    int rval = Test->global_result;
    delete Test;
    return rval;
}
Example #18
0
        std::vector<Property> get_all_properties(const wchar_t * i_query)
        {
            std::vector<Property> props;
            auto                  query_results = execute_query(i_query);
            for (const auto & result : query_results)
            {
                TESTITY_COM_CALL(result->BeginEnumeration(0));

                for (;;)
                {
                    CComBSTR    prop_name;
                    CComVariant prop_value;
                    if (result->Next(0, &prop_name, &prop_value, NULL, NULL) != ERROR_SUCCESS)
                    {
                        break;
                    }
                    prop_value.ChangeType(VT_BSTR);

                    Property prop;
                    prop.m_name  = ConvertBSTRToMBS(prop_name);
                    prop.m_value = ConvertBSTRToMBS(prop_value.bstrVal);
                    props.push_back(std::move(prop));
                }

                TESTITY_COM_CALL(result->EndEnumeration());
            }
            return std::move(props);
        }
Example #19
0
int main() {
  CassCluster* cluster = create_cluster();
  CassSession* session = cass_session_new();
  CassFuture* close_future = NULL;

  const Pair items[] = { { "apple", 1 }, { "orange", 2 }, { "banana", 3 }, { "mango", 4 }, { NULL, 0 } };

  if (connect_session(session, cluster) != CASS_OK) {
    cass_cluster_free(cluster);
    cass_session_free(session);
    return -1;
  }

  execute_query(session,
                "CREATE KEYSPACE examples WITH replication = { \
                'class': 'SimpleStrategy', 'replication_factor': '3' };");

  execute_query(session,
                "CREATE TABLE examples.maps (key text, \
                items map<text, int>, \
                PRIMARY KEY (key))");


  insert_into_maps(session, "test", items);
  select_from_maps(session, "test");

  close_future = cass_session_close(session);
  cass_future_wait(close_future);
  cass_future_free(close_future);

  cass_cluster_free(cluster);
  cass_session_free(session);

  return 0;
}
Example #20
0
/**
  \details Update Mapistore URI for existing FMID

  \param ictx valid pointer to indexing context
  \param username samAccountName for current user
  \param fmid FMID to update
  \param mapistore_URI mapistore URI string to associate with fmid

  \return MAPISTORE_SUCCESS on success,
	  MAPISTORE_ERR_NOT_FOUND if FMID entry doesn't exists
	  MAPISTORE_ERR_NOT_INITIALIZED if ictx pointer is invalid (NULL)
	  MAPISTORE_ERR_INVALID_PARAMETER in case other parameters are not valid
	  MAPISTORE_ERR_DATABASE_OPS in case of MySQL error
 */
static enum mapistore_error mysql_record_update(struct indexing_context *ictx,
						const char *username,
						uint64_t fmid,
						const char *mapistore_URI)
{
	int		ret;
	char		*sql;
	TALLOC_CTX	*mem_ctx;

	/* Sanity checks */
	MAPISTORE_RETVAL_IF(!ictx, MAPISTORE_ERR_NOT_INITIALIZED, NULL);
	MAPISTORE_RETVAL_IF(!username, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
	MAPISTORE_RETVAL_IF(!fmid, MAPISTORE_ERR_INVALID_PARAMETER, NULL);
	MAPISTORE_RETVAL_IF(!mapistore_URI, MAPISTORE_ERR_INVALID_PARAMETER, NULL);

	mem_ctx = talloc_new(NULL);
	sql = talloc_asprintf(mem_ctx,
		"UPDATE %s "
		"SET url = '%s' "
		"WHERE username = '******' AND fmid = %"PRIu64,
		INDEXING_TABLE, _sql(mem_ctx, mapistore_URI), _sql(mem_ctx, username), fmid);

	ret = execute_query(MYSQL(ictx), sql);
	MAPISTORE_RETVAL_IF(ret != MYSQL_SUCCESS, MAPISTORE_ERR_DATABASE_OPS, mem_ctx);

	talloc_free(mem_ctx);

	/* did we updated anything? */
	/* TODO: Move mysql_affected_rows() in execute_query() */
	if (mysql_affected_rows(MYSQL(ictx)) == 0) {
		return MAPISTORE_ERR_NOT_FOUND;
	}

	return MAPISTORE_SUCCESS;
}
Example #21
0
        std::vector<std::string> get_properties(
          const wchar_t * i_query, const std::vector<const wchar_t *> & i_property_names)
        {
            auto                     query_results = execute_query(i_query);
            std::vector<std::string> value_strs;
            value_strs.resize(i_property_names.size());
            for (size_t property_index = 0; property_index < i_property_names.size();
                 property_index++)
            {
                for (const auto & result : query_results)
                {
                    auto & value_str = value_strs[property_index];
                    if (value_str.length() > 0)
                    {
                        value_str += ", ";
                    }

                    CComVariant value;
                    CIMTYPE     value_type;
                    TESTITY_COM_CALL(
                      result->Get(i_property_names[property_index], 0, &value, &value_type, NULL));
                    value.ChangeType(VT_BSTR);
                    value_str += ConvertBSTRToMBS(value.bstrVal);
                }
            }
            return value_strs;
        }
Example #22
0
void buildfromfile()
{
	QSqlQuery query(db);
#ifdef REDUCE_THRU_DIACRITICS
	QString stmt=QString("SELECT stem.id, stem.name, stem_category.category_id, stem_category.raw_data FROM stem, stem_category WHERE stem.id=stem_category.stem_id ORDER BY stem.id ASC");
#else
	QString stmt=QString("SELECT stem.id, stem.name, stem_category.category_id FROM stem, stem_category WHERE stem.id=stem_category.stem_id ORDER BY stem.id ASC");
#endif
	QString name,raw_data;
	long category_id;
	long long  stem_id, last_id;
	if (!execute_query(stmt,query))
		return;
	//out<<QDateTime::currentDateTime().time().toString()<<"\n";
	StemNode * node = NULL;
	int index=0;
	last_id=-1;
	int total=query.size(), current=0;
	while (query.next())
	{
		stem_id=query.value(0).toULongLong();
		if (last_id!=stem_id)
		{
			if (last_id!=-1)
			{
				database_info.trie_nodes->insert(index,*node);
				delete node;
				database_info.Stem_Trie->store(name,index);
				index++;
			}
			last_id=stem_id;
			node=new StemNode();
			node->key=name;
			node->stem_id=stem_id;
		}
		name=query.value(1).toString();
		category_id=query.value(2).toLongLong();
#ifdef REDUCE_THRU_DIACRITICS
		raw_data=query.value(3).toString();
		node->add_info(category_id,raw_data);
#else
		node->add_info(category_id);
#endif
		current++;
		prgsIFC->report((double)current/total*100+0.5);
	}
	//out<<QDateTime::currentDateTime().time().toString()<<"\n";
	database_info.Stem_Trie->save(trie_path.toStdString().data());
	QFile file(trie_list_path.toStdString().data());
	if (file.open(QIODevice::WriteOnly))
	{
		QDataStream out(&file);   // we will serialize the data into the file
		out << cache_version();
		out << *(database_info.trie_nodes);
		file.close();
	}
	else
		error <<"Unexpected Error: Unable to write TRIE to file\n";
}
int Mariadb_nodes::set_slave(MYSQL * conn, char master_host[], int master_port, char log_file[], char log_pos[])
{
    char str[1024];
    sprintf(str, setup_slave, master_host, log_file, log_pos, master_port);

    printf("Setup slave SQL: %s\n", str);
    return(execute_query(conn, str));
}
void SqliteWorkHorse::initDatabase(){

	int rc = sqlite3_open_v2(this->plow->getDatabaseFile().c_str(), &db,  SQLITE_OPEN_FULLMUTEX | SQLITE_OPEN_READONLY,0);
	if( rc ){
		fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
		return;
	}
	sqlite3_enable_load_extension(db,1);
	sqlite3_enable_load_extension(db,1);
	#ifdef WIN32
		execute_query(db,"SELECT load_extension('mod_spatialite')");
	#else
		execute_query(db,"SELECT load_extension('/usr/local/lib/mod_spatialite')");
	#endif
	std::stringstream query_ss;
	query_ss << "SELECT load_extension('" << this->plow->getExtensionLocation() << "')";
	std::cout << query_ss.str() << std::endl;
	execute_query(query_ss.str().c_str());
}
Example #25
0
void on_create_keyspace(CassFuture* future, void* data) {
  CassError code = cass_future_error_code(future);
  if (code != CASS_OK) {
    print_error(future);
  }

  execute_query((CassSession*)data,
                "USE examples",
                on_set_keyspace);
}
int player_offense_stats_t_read( sqlite3 *db, player_offense_stats_s *player_offense_stats )
{
     static char query[]   = "SELECT Pass_Attempts, Completions, Interceptions, Pass_Yards, Pass_Touchdowns, Rush_Attempts, Rush_Yards, Rush_Touchdowns, Receptions, Receiving_Yards, Receiving_Touchdowns "
          /**/               "FROM   Player_Offense_Stats_T "
          /**/               "WHERE  Player_Id      = ? "
          /**/               "AND    Season       = ? "
          /**/               "AND    Bowl_Game = ? ";

     return execute_query( db, query, player_offense_stats_t_read_bindings, player_offense_stats, player_offense_stats_t_read_retrieve, player_offense_stats );
}
int Mariadb_nodes::set_repl_user()
{
    int global_result = 0;
    global_result += connect();
    for (int i = 0; i < N; i++) {
        global_result += execute_query(nodes[i], create_repl_user);
    }
    close_connections();
    return(global_result);
}
static bool
get_agent_uri( uint64_t datapath_id, char **uri ) {
  debug( "Retrieving agent's URI ( datapath_id = %#" PRIx64 ", uri = %p ).", datapath_id, uri );

  assert( uri != NULL );

  MYSQL_RES *result = NULL;

  *uri = NULL;

  bool ret = execute_query( db, "select uri from agents where datapath_id = %" PRIu64, datapath_id );
  if ( !ret ) {
    goto error;
  }

  result = mysql_store_result( db );
  if ( result == NULL ) {
    error( "Failed to retrieve result from database ( %s ).", mysql_error( db ) );
    goto error;
  }

  assert( mysql_num_fields( result ) == 1 );
  if ( mysql_num_rows( result ) == 0 ) {
    warn( "Failed to retrieve agent information ( datapath_id = %#" PRIx64 " ).", datapath_id );
    goto error;
  }

  MYSQL_ROW row = mysql_fetch_row( result );
  if ( row != NULL ) {
    *uri = xstrdup( row[ 0 ] );
  }
  else {
    error( "Failed to fetch data." );
    goto error;
  }

  mysql_free_result( result );

  debug( "Agent's URI is retrieved ( datapath_id = %#" PRIx64 ", uri = %s ).", datapath_id, *uri );

  return true;

error:
  error( "Failed to retrieve agent's URI ( datapath_id = %#" PRIx64 ", uri = %p ).", datapath_id, uri );

  if ( result != NULL ) {
    mysql_free_result( result );
  }
  if ( *uri != NULL ) {
    xfree( *uri );
    *uri = NULL;
  }

  return false;
}
int player_game_defense_stats_t_read( sqlite3 *db, player_game_defense_stats_s *player_game_defense_stats )
{
     static char query[]   = "SELECT Sacks, Interceptions, Return_Yards, Return_Touchdowns "
          /**/               "FROM   Player_Game_Defense_Stats_T "
          /**/               "WHERE  Player_Id    = ? "
          /**/               "AND    Season       = ? "
          /**/               "AND    Week         = ? "
          /**/               "AND    Game         = ? ";

     return execute_query( db, query, player_game_defense_stats_t_read_bindings, player_game_defense_stats, player_game_defense_stats_t_read_retrieve, player_game_defense_stats );
}
Example #30
0
void MetadataStorage::init_config(const char* creation_datetime)
{
    // Create table and insert data into it

    std::stringstream insert;
    insert << "INSERT INTO akumuli_configuration (name, value, comment)" << std::endl;
    insert << "\tSELECT 'creation_time' as name, '" << creation_datetime << "' as value, "
           << "'Compression threshold value' as comment" << std::endl;
    std::string insert_query = insert.str();
    execute_query(insert_query);
}