本文整理汇总了C++中CloseDB函数的典型用法代码示例。如果您正苦于以下问题:C++ CloseDB函数的具体用法?C++ CloseDB怎么用?C++ CloseDB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了CloseDB函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SQLConn
SQLConn(Module* m, const SQLhost& hi)
: mod(m), host(hi), login(NULL), sock(NULL), context(NULL)
{
if (OpenDB())
{
std::string query("USE " + host.name);
if (tds_submit_query(sock, query.c_str()) == TDS_SUCCEED)
{
if (tds_process_simple_query(sock) != TDS_SUCCEED)
{
LoggingMutex->Lock();
ServerInstance->Logs->Log("m_mssql",LOG_DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
LoggingMutex->Unlock();
CloseDB();
}
}
else
{
LoggingMutex->Lock();
ServerInstance->Logs->Log("m_mssql",LOG_DEFAULT, "WARNING: Could not select database " + host.name + " for DB with id: " + host.id);
LoggingMutex->Unlock();
CloseDB();
}
}
else
{
LoggingMutex->Lock();
ServerInstance->Logs->Log("m_mssql",LOG_DEFAULT, "WARNING: Could not connect to DB with id: " + host.id);
LoggingMutex->Unlock();
CloseDB();
}
}
示例2: mysql_init
MYSQL *OpenDB(char *pHost, char *pUser, char *pPasswd, char *pDB, char *pUnixSocket, unsigned long lClientFlag, unsigned int nPort)
{
MYSQL *pMySql = mysql_init(NULL);
if (!pMySql)
{
SystemErrorInfor("OpenDB", errno);
return NULL;
}
if (!mysql_real_connect(pMySql, pHost, pUser, pPasswd, pDB, nPort, pUnixSocket, lClientFlag))
{
ErrorInfor("OpenDB-1", (char *)mysql_error(pMySql));
CloseDB(pMySql);
return NULL;
}
if (mysql_autocommit(pMySql, 0) != 0)
{
ErrorInfor("OpenDB-2", (char *)mysql_error(pMySql));
CloseDB(pMySql);
return NULL;
}
return pMySql;
}
示例3: test_migrate_unqualified_names
void test_migrate_unqualified_names(void)
{
DBHandle *db = setup(true);
assert_int_equal(WriteDB(db, "foo", &dummy_event, sizeof(dummy_event)), true);
assert_int_equal(WriteDB(db, "q.bar", &dummy_event, sizeof(dummy_event)), true);
CloseDB(db);
assert_int_equal(OpenDB(&db, dbid_bundles), true);
/* Old entry migrated */
assert_int_equal(HasKeyDB(db, "foo", strlen("foo") + 1), false);
assert_int_equal(HasKeyDB(db, "default.foo", strlen("default.foo") + 1), true);
Event read_value = { 0 };
ReadDB(db, "default.foo", &read_value, sizeof(read_value));
assert_memory_equal(&read_value, &dummy_event, sizeof(dummy_event));
/* New entry preserved */
assert_int_equal(HasKeyDB(db, "q.bar", strlen("q.bar") + 1), true);
memset(&read_value, 0, sizeof(read_value));
ReadDB(db, "q.bar", &read_value, sizeof(read_value));
assert_memory_equal(&read_value, &dummy_event, sizeof(dummy_event));
/* Version marker */
assert_int_equal(HasKeyDB(db, "version", strlen("version") + 1), true);
CloseDB(db);
}
示例4: test_no_migration
static void test_no_migration(void)
{
DBHandle *db = setup(true);
CloseDB(db);
/* Migration on empty DB should produce single "version" key */
assert_int_equal(OpenDB(&db, dbid_lastseen), true);
DBCursor *cursor;
assert_int_equal(NewDBCursor(db, &cursor), true);
char *key;
void *value;
int ksize, vsize;
while (NextDB(cursor, &key, &ksize, &value, &vsize))
{
assert_int_equal(ksize, strlen("version") + 1);
assert_string_equal(key, "version");
assert_int_equal(vsize, 2);
assert_string_equal(value, "1");
}
assert_int_equal(DeleteDBCursor(cursor), true);
CloseDB(db);
}
示例5: PurgeCurrentLastSeen
static bool PurgeCurrentLastSeen()
{
CF_DB *db_conn = NULL;
CF_DBC *db_cursor = NULL;
char *key = NULL;
void *value = NULL;
int ksize = 0, vsize = 0;
if (!OpenDB(&db_conn, dbid_lastseen))
{
Log(LOG_LEVEL_ERR, "Unable to open lastseen db");
return false;
}
if (!NewDBCursor(db_conn, &db_cursor))
{
Log(LOG_LEVEL_ERR, "Unable to scan lastseen db");
CloseDB(db_conn);
return false;
}
while (NextDB(db_cursor, &key, &ksize, &value, &vsize))
{
/* Only read the 'quality of connection' entries */
if (key[0] != 'q')
{
continue;
}
time_t then = 0;
if (value != NULL)
{
if (sizeof(KeyHostSeen) < vsize)
{
Log(LOG_LEVEL_ERR, "Invalid entry in lastseen database.");
continue;
}
KeyHostSeen entry = { 0 };
memcpy(&entry, value, vsize);
then = entry.lastseen;
}
if (then - START_TIME > NHOSTS)
{
DBCursorDeleteEntry(db_cursor);
Log(LOG_LEVEL_DEBUG, "Deleting expired entry for %s", key);
continue;
}
}
DeleteDBCursor(db_cursor);
CloseDB(db_conn);
return true;
}
示例6: test_migrate_single
void test_migrate_single(const char *expected_old_key,
const char *expected_quality_key)
{
/* Test migration of single entry */
DBHandle *db = setup(true);
KeyHostSeen0 khs0 = {
.q = 666777.0,
.expect = 12345.0,
.var = 6543210.0,
};
strcpy(khs0.address, "1.2.3.4");
assert_int_equal(WriteDB(db, expected_old_key, &khs0, sizeof(khs0)), true);
CloseDB(db);
assert_int_equal(OpenDB(&db, dbid_lastseen), true);
/* Old entry migrated */
assert_int_equal(HasKeyDB(db, expected_old_key,
strlen(expected_old_key) + 1), false);
/* Version marker */
assert_int_equal(HasKeyDB(db, "version", strlen("version") + 1), true);
/* Incoming connection quality */
KeyHostSeen khs;
assert_int_equal(ReadDB(db, expected_quality_key, &khs, sizeof(khs)), true);
assert_int_equal(khs.lastseen, 666777);
assert_double_close(khs.Q.q, 12345.0);
assert_double_close(khs.Q.expect, 12345.0);
assert_double_close(khs.Q.var, 6543210.0);
/* Address mapping */
char address[CF_BUFSIZE];
assert_int_equal(ReadDB(db, KEYHASH_KEY, address, sizeof(address)), true);
assert_string_equal(address, "1.2.3.4");
/* Reverse mapping */
char keyhash[CF_BUFSIZE];
assert_int_equal(ReadDB(db, "a1.2.3.4", keyhash, sizeof(keyhash)), true);
assert_string_equal(keyhash, KEYHASH);
CloseDB(db);
}
void test_migrate_incoming(void)
{
test_migrate_single(KEYHASH_IN, QUALITY_IN);
}
示例7: test_setup
static void test_setup(void)
{
snprintf(CFWORKDIR, CF_BUFSIZE, "/tmp/changes_migration_test.XXXXXX");
mkdtemp(CFWORKDIR);
char state_dir[PATH_MAX];
snprintf(state_dir, sizeof(state_dir), "%s/state", CFWORKDIR);
mkdir(state_dir, 0755);
CF_DB *db;
assert_true(OpenDB(&db, dbid_checksums));
// Hand crafted from the old version of NewIndexKey().
char checksum_key[NO_FILES][30] =
{
{ 'M','D','5','\0','\0','\0','\0','\0',
'/','e','t','c','/','h','o','s','t','s','\0' },
{ 'M','D','5','\0','\0','\0','\0','\0',
'/','e','t','c','/','p','a','s','s','w','d','\0' },
{ 'M','D','5','\0','\0','\0','\0','\0',
'/','f','i','l','e','1','\0' },
{ 'M','D','5','\0','\0','\0','\0','\0',
'/','f','i','l','e','2','\0' },
};
for (int c = 0; c < NO_FILES; c++)
{
int ksize = CHANGES_HASH_FILE_NAME_OFFSET + strlen(checksum_key[c] + CHANGES_HASH_FILE_NAME_OFFSET) + 1;
int vsize = strlen(CHECKSUM_VALUE[c]) + 1;
assert_true(WriteComplexKeyDB(db, checksum_key[c], ksize,
CHECKSUM_VALUE[c], vsize));
}
CloseDB(db);
assert_true(OpenDB(&db, dbid_filestats));
char *filestat_key[NO_FILES] =
{
"/etc/hosts",
"/etc/passwd",
"/file1",
"/file2",
};
filestat_value.st_uid = 4321;
memset(&filestat_value, 0, sizeof(filestat_value));
for (int c = 0; c < NO_FILES; c++)
{
assert_true(WriteDB(db, filestat_key[c],
&filestat_value, sizeof(filestat_value)));
}
CloseDB(db);
}
示例8: Mon_DumpSlowlyVaryingObservations
static void Mon_DumpSlowlyVaryingObservations(void)
{
CF_DB *dbp;
CF_DBC *dbcp;
FILE *fout;
char *key;
void *stored;
int ksize, vsize;
char name[CF_BUFSIZE];
if (!OpenDB(&dbp, dbid_static))
{
return;
}
snprintf(name, CF_BUFSIZE - 1, "%s%cstate%cstatic_data", CFWORKDIR, FILE_SEPARATOR, FILE_SEPARATOR);
if ((fout = fopen(name, "w")) == NULL)
{
Log(LOG_LEVEL_ERR, "Unable to save discovery data in '%s'. (fopen: %s)", name, GetErrorStr());
CloseDB(dbp);
return;
}
/* Acquire a cursor for the database. */
if (!NewDBCursor(dbp, &dbcp))
{
Log(LOG_LEVEL_INFO, "Unable to scan class db");
CloseDB(dbp);
return;
}
while (NextDB(dbcp, &key, &ksize, &stored, &vsize))
{
char buf[CF_MAXVARSIZE], lval[CF_MAXVARSIZE], rval[CF_BUFSIZE];
strncpy(buf, key, CF_MAXVARSIZE - 1);
sscanf(buf, "%s:", lval);
if (stored != NULL)
{
strncpy(rval, stored, CF_BUFSIZE - 1);
fprintf(fout, "%s:%s\n", lval, rval);
}
}
DeleteDBCursor(dbcp);
CloseDB(dbp);
fclose(fout);
}
示例9: memset
static Averages *GetCurrentAverages(char *timekey)
{
CF_DB *dbp;
static Averages entry;
if (!OpenDB(&dbp, dbid_observations))
{
return NULL;
}
memset(&entry, 0, sizeof(entry));
AGE++;
WAGE = AGE / SECONDS_PER_WEEK * CF_MEASURE_INTERVAL;
if (ReadDB(dbp, timekey, &entry, sizeof(Averages)))
{
int i;
for (i = 0; i < CF_OBSERVABLES; i++)
{
Log(LOG_LEVEL_DEBUG, "Previous values (%lf,..) for time index '%s'", entry.Q[i].expect, timekey);
}
}
else
{
Log(LOG_LEVEL_DEBUG, "No previous value for time index '%s'", timekey);
}
CloseDB(dbp);
return &entry;
}
示例10: CloseDB
BOOL CMyDataBase::ReConnDB()
{
CloseDB();
return ConnDB();
}
示例11: CloseAllDB
void CloseAllDB(void)
/* Closes all open DB handles */
{ CF_DB *dbp = NULL;
int i = 0;
Debug("CloseAllDB()\n");
while (true)
{
if (!GetDBHandle(&dbp))
{
FatalError("CloseAllDB: Could not pop next DB handle");
}
if (dbp == NULL)
{
break;
}
if (!CloseDB(dbp))
{
CfOut(cf_error, "", "!! CloseAllDB: Could not close DB with this handle");
}
i++;
}
Debug("Closed %d open DB handles\n", i);
}
示例12: test_iter_delete_entry
void test_iter_delete_entry(void **state)
{
/* Test that deleting entry under cursor does not interrupt iteration */
CF_DB *db;
assert_int_equal(OpenDB(&db, dbid_classes), true);
assert_int_equal(WriteDB(db, "foobar", "abc", 3), true);
assert_int_equal(WriteDB(db, "bazbaz", "def", 3), true);
assert_int_equal(WriteDB(db, "booo", "ghi", 3), true);
CF_DBC *cursor;
assert_int_equal(NewDBCursor(db, &cursor), true);
char *key;
int ksize;
void *value;
int vsize;
assert_int_equal(NextDB(db, cursor, &key, &ksize, &value, &vsize), true);
assert_int_equal(DBCursorDeleteEntry(cursor), true);
assert_int_equal(NextDB(db, cursor, &key, &ksize, &value, &vsize), true);
assert_int_equal(NextDB(db, cursor, &key, &ksize, &value, &vsize), true);
assert_int_equal(DeleteDBCursor(db, cursor), true);
CloseDB(db);
}
示例13: OpenDB
bool OpenDB()
{
CloseDB();
TDSCONNECTION* conn = NULL;
login = tds_alloc_login();
tds_set_app(login, "TSQL");
tds_set_library(login,"TDS-Library");
tds_set_host(login, "");
tds_set_server(login, host.host.c_str());
tds_set_server_addr(login, host.host.c_str());
tds_set_user(login, host.user.c_str());
tds_set_passwd(login, host.pass.c_str());
tds_set_port(login, host.port);
tds_set_packet(login, 512);
context = tds_alloc_context(this);
context->msg_handler = HandleMessage;
context->err_handler = HandleError;
sock = tds_alloc_socket(context, 512);
tds_set_parent(sock, NULL);
conn = tds_read_config_info(NULL, login, context->locale);
if (tds_connect(sock, conn) == TDS_SUCCEED)
{
tds_free_connection(conn);
return 1;
}
tds_free_connection(conn);
return 0;
}
示例14: RemoveHostFromLastSeen
bool RemoveHostFromLastSeen(const char *hostname, char *hostkey)
{
char ip[CF_BUFSIZE];
char digest[CF_BUFSIZE] = { 0 };
if (!hostkey)
{
strcpy(ip, Hostname2IPString(hostname));
IPString2KeyDigest(ip, digest);
}
else
{
snprintf(digest, sizeof(digest), "%s", hostkey);
}
CF_DB *dbp;
char key[CF_BUFSIZE];
if (!OpenDB(&dbp, dbid_lastseen))
{
CfOut(cf_error, "", " !! Unable to open last seen DB");
return false;
}
snprintf(key, CF_BUFSIZE, "-%s", digest);
DeleteComplexKeyDB(dbp, key, strlen(key) + 1);
snprintf(key, CF_BUFSIZE, "+%s", digest);
DeleteComplexKeyDB(dbp, key, strlen(key) + 1);
CloseDB(dbp);
return true;
}
示例15: test_newentry
static void test_newentry(void **context)
{
setup();
UpdateLastSawHost("SHA-12345", "127.0.0.64", true, 666);
DBHandle *db;
OpenDB(&db, dbid_lastseen);
KeyHostSeen q;
assert_int_equal(ReadDB(db, "qiSHA-12345", &q, sizeof(q)), true);
assert_int_equal(q.lastseen, 666);
assert_double_close(q.Q.q, 0.0);
assert_double_close(q.Q.dq, 0.0);
assert_double_close(q.Q.expect, 0.0);
assert_double_close(q.Q.var, 0.0);
assert_int_equal(ReadDB(db, "qoSHA-12345", &q, sizeof(q)), false);
char address[CF_BUFSIZE];
assert_int_equal(ReadDB(db, "kSHA-12345", address, sizeof(address)), true);
assert_string_equal(address, "127.0.0.64");
char hostkey[CF_BUFSIZE];
assert_int_equal(ReadDB(db, "a127.0.0.64", hostkey, sizeof(hostkey)), true);
assert_string_equal(hostkey, "SHA-12345");
CloseDB(db);
}