• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ CloseDB函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中CloseDB函数的典型用法代码示例。如果您正苦于以下问题:C++ CloseDB函数的具体用法?C++ CloseDB怎么用?C++ CloseDB使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了CloseDB函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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();
		}
	}
开发者ID:H7-25,项目名称:inspircd,代码行数:32,代码来源:m_mssql.cpp


示例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;
}
开发者ID:yangchenzhong,项目名称:im,代码行数:25,代码来源:db.c


示例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);
}
开发者ID:JarleB,项目名称:core,代码行数:26,代码来源:dbm_migration_bundles_test.c


示例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);
}
开发者ID:AsherBond,项目名称:core,代码行数:29,代码来源:lastseen_migration_test.c


示例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;
}
开发者ID:GregorioDiStefano,项目名称:core,代码行数:57,代码来源:lastseen_threaded_load.c


示例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);
}
开发者ID:AsherBond,项目名称:core,代码行数:54,代码来源:lastseen_migration_test.c


示例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);
}
开发者ID:lra,项目名称:core,代码行数:53,代码来源:changes_migration_test.c


示例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);
}
开发者ID:markburgess,项目名称:Cellibrium,代码行数:52,代码来源:history.c


示例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;
}
开发者ID:arcimboldo,项目名称:cfengine,代码行数:32,代码来源:env_monitor.c


示例10: CloseDB

BOOL CMyDataBase::ReConnDB()
{

	CloseDB();
	return ConnDB();

}
开发者ID:cugxiangzhenwei,项目名称:TSP_Zhenwei,代码行数:7,代码来源:MyDBConn.cpp


示例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);
}
开发者ID:Kegeruneku,项目名称:Cfengine-debian,代码行数:30,代码来源:dbm_api.c


示例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);
}
开发者ID:joegen,项目名称:sipx-externals,代码行数:30,代码来源:db_test.c


示例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;
	}
开发者ID:H7-25,项目名称:inspircd,代码行数:34,代码来源:m_mssql.cpp


示例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;
}
开发者ID:gsprint,项目名称:core,代码行数:32,代码来源:instrumentation.c


示例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);
}
开发者ID:FancsalMelinda,项目名称:core,代码行数:30,代码来源:lastseen_test.c


示例16: _MonUpload

static void _MonUpload(const char *file, const char *metafile) {
  DBG_Struct *dbg;
  char *id,*buf;
  size_t size;

  if (!g_file_get_contents(file, &buf, &size, NULL)) {
    g_warning("cannot read file:%s",file);
    exit(1);
  }

  dbg = GetDBG_monsys();
  dbg->dbt = NewNameHash();

  if (OpenDB(dbg) != MCP_OK) {
    g_warning("OpenDB failure");
    exit(1);
  }
  monblob_setup(dbg, FALSE);

  TransactionStart(dbg);

  id = monblob_import_mem(dbg, NULL, 0, "monupload.bin", NULL, 0, buf, size);
  g_free(buf);

  TransactionEnd(dbg);
  CloseDB(dbg);

  AddMetaData(id, metafile);
  xfree(id);
}
开发者ID:montsuqi,项目名称:panda,代码行数:30,代码来源:monupload.c


示例17: Address2Hostkey

bool Address2Hostkey(const char *address, char *result)
{
    result[0] = '\0';
    if ((strcmp(address, "127.0.0.1") == 0) || (strcmp(address, "::1") == 0) || (strcmp(address, VIPADDRESS) == 0))
    {
        if (PUBKEY)
        {
            unsigned char digest[EVP_MAX_MD_SIZE + 1];
            HashPubKey(PUBKEY, digest, CF_DEFAULT_DIGEST);
            HashPrintSafe(CF_DEFAULT_DIGEST, digest, result);
            return true;
        }
        else
        {
            return false;
        }
    }

    DBHandle *db;
    if (!OpenDB(&db, dbid_lastseen))
    {
        return false;
    }

    bool ret = Address2HostkeyInDB(db, address, result);
    CloseDB(db);
    return ret;
}
开发者ID:JarleB,项目名称:core,代码行数:28,代码来源:lastseen.c


示例18: CloseDB

CAlljoynMob::~CAlljoynMob() 
{
	if (m_pBus) {
		delete m_pBus;
		m_pBus = NULL;
	}
	CloseDB();
}
开发者ID:arcookie,项目名称:mob,代码行数:8,代码来源:AlljoynMob.cpp


示例19: SQLConn

	SQLConn(InspIRCd* SI, Module* m, const SQLhost& hi)
	: ServerInstance(SI), mod(m), host(hi)
	{
		if (OpenDB() != SQLITE_OK)
		{
			ServerInstance->Logs->Log("m_sqlite3",DEFAULT, "WARNING: Could not open DB with id: " + host.id);
			CloseDB();
		}
	}
开发者ID:thepaul,项目名称:inspircd-deb,代码行数:9,代码来源:m_sqlite3.cpp


示例20: DeleteIpFromLastSeen

/**
 * @brief removes all traces of host 'ip' from lastseen DB
 *
 * @param[in]     ip : either in (SHA/MD5 format)
 * @param[in,out] digest: return corresponding digest of input host.
 *                        If NULL, return nothing
 * @retval true if entry was deleted, false otherwise
 */
bool DeleteIpFromLastSeen(const char *ip, char *digest)
{
    DBHandle *db;
    bool res = false;

    if (!OpenDB(&db, dbid_lastseen))
    {
        Log(LOG_LEVEL_ERR, "Unable to open lastseen database");
        return false;
    }

    char bufkey[CF_BUFSIZE + 1];
    char bufhost[CF_BUFSIZE + 1];

    strcpy(bufhost, "a");
    strlcat(bufhost, ip, CF_BUFSIZE);

    char key[CF_BUFSIZE];
    if (ReadDB(db, bufhost, &key, sizeof(key)) == true)
    {
        strcpy(bufkey, "k");
        strlcat(bufkey, key, CF_BUFSIZE);
        if (HasKeyDB(db, bufkey, strlen(bufkey) + 1) == false)
        {
            res = false;
            goto clean;
        }
        else
        {
            if (digest != NULL)
            {
                strcpy(digest, bufkey);
            }
            DeleteDB(db, bufkey);
            DeleteDB(db, bufhost);
            res = true;
        }
    }
    else
    {
        res = false;
        goto clean;
    }

    strcpy(bufkey, "qi");
    strlcat(bufkey, key, CF_BUFSIZE);
    DeleteDB(db, bufkey);

    strcpy(bufkey, "qo");
    strlcat(bufkey, key, CF_BUFSIZE);
    DeleteDB(db, bufkey);

clean:
    CloseDB(db);
    return res;
}
开发者ID:JarleB,项目名称:core,代码行数:64,代码来源:lastseen.c



注:本文中的CloseDB函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ CloseDesktop函数代码示例发布时间:2022-05-30
下一篇:
C++ CloseConnection函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap