コード例 #1
0
ファイル: KSO3RoleDBTools.cpp プロジェクト: 1suming/pap2
int KSO3RoleDBTools::GetRoleAllInfoToCompare(BYTE* byBaseInfoData, unsigned long ulBaseInfoSize, BYTE* byExtInfoData, unsigned long ulExtInfoSize, char szTableName[], char szTimeFileName[], DWORD dwID)
{
    BOOL                        bResult         = false;
    BOOL                        bRetCode        = false;
    int                         nRetCode        = false;
    MYSQL_RES*                  pQueryRes       = NULL;
    MYSQL_ROW                   QueryRow;

    nRetCode = snprintf(
        m_szSQL, sizeof(m_szSQL), "select %s, %s, %s, %s, %s, %s from %s where %s = %u", 
        KG_ID_FIELD_NAME,           KG_NAME_FIELD_NAME,     KG_ACCOUNT_FIELD_NAME, 
        KG_BASE_INFO_FIELD_NAME,    KG_EXT_INFO_FIELD_NAME, szTimeFileName, szTableName, KG_ID_FIELD_NAME, dwID
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    KGLOG_PROCESS_ERROR(bRetCode);

    pQueryRes = mysql_use_result(m_pDBHandle);
    KGLOG_PROCESS_ERROR(pQueryRes);


    unsigned long*  pulLengths           = NULL;

    QueryRow = mysql_fetch_row(pQueryRes);
    if (QueryRow == NULL)
    {
        goto Exit1;
    }

    pulLengths = mysql_fetch_lengths(pQueryRes);
    KGLOG_PROCESS_ERROR(pulLengths);

    KGLOG_PROCESS_ERROR(pulLengths[1] < _NAME_LEN);
    KGLOG_PROCESS_ERROR(pulLengths[2] < _NAME_LEN);

    if (pulLengths[3] != sizeof(KBaseInfo_Old))
    {
        KGLogPrintf(KGLOG_INFO, "The RoleDBDate is not 11 Version, please Use The 11 version RoleDB!");
        KGLOG_PROCESS_ERROR(false);// 屏蔽转换一半继续转换的功能,如果转换失败在这,请要重新恢复数据库.
        m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_bHadUpdateBaseInfo = true;
    }

    ASSERT(QueryRow[0]);
    ASSERT(QueryRow[1]);
    ASSERT(QueryRow[2]);
    ASSERT(QueryRow[3]);
    ASSERT(QueryRow[5]);

    //比较KBaseInfo_Old
    if(pulLengths[3] != ulBaseInfoSize)
    {
        KGLogPrintf(KGLOG_INFO, "BaseInfoSize Error");
    }
    nRetCode = memcmp(QueryRow[3], byBaseInfoData, pulLengths[3]);
    if (nRetCode != 0)
    {
        KGLogPrintf(KGLOG_INFO, "BaseInfo Error");
    }
    if (QueryRow[4] != NULL)
    {
        if (pulLengths[4] != ulExtInfoSize)
        {
            KGLogPrintf(KGLOG_INFO, "ExtInfo Size Error");
        }
        nRetCode = memcmp(QueryRow[4], byExtInfoData, pulLengths[4]);
        if (nRetCode != 0)
        {
            KGLogPrintf(KGLOG_INFO, "ExtInfo Error");
        }
    }

Exit1:
    bResult = true;
Exit0:

    if (pQueryRes)
    {
        mysql_free_result(pQueryRes);
        pQueryRes = NULL;
    }
    return bResult;
}
コード例 #2
0
ファイル: KSO3RoleDBTools.cpp プロジェクト: 1suming/pap2
int KSO3RoleDBTools::CheckRoleTable()
{
    int     nResult = false;
    BOOL    bRetCode    = 0;
    int     nStrLen     = 0;

    nStrLen = snprintf(m_szSQL, sizeof(m_szSQL), 
        "create table if not exists %s "
        "("
        "   %s bigint not null,"
        "   %s varchar(32) not null,"
        "   %s varchar(32) not null,"
        "   %s blob not null,"
        "   %s blob,"
        "   %s datetime not null,"
        "   primary key (%s), index (%s), unique (%s)"
        ");",
        ROLE_TABLE_NAME,            KG_ID_FIELD_NAME,         KG_NAME_FIELD_NAME, 
        KG_ACCOUNT_FIELD_NAME,      KG_BASE_INFO_FIELD_NAME,  KG_EXT_INFO_FIELD_NAME, 
        KG_LAST_MODIFY_FIELD_NAME,  KG_ID_FIELD_NAME,         KG_ACCOUNT_FIELD_NAME,    KG_NAME_FIELD_NAME
    );
    KGLOG_PROCESS_ERROR(nStrLen > 0 && nStrLen < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    if (!bRetCode)
    {
        KGLogPrintf(
            KGLOG_ERR, 
            "DB ERROR when try to create table \'%s\'\n", 
            ROLE_TABLE_NAME
        );
        goto Exit0;
    }

    nStrLen = snprintf(m_szSQL, sizeof(m_szSQL), 
        "create table if not exists %s "
        "("
        "   %s bigint not null auto_increment,"
        "   %s varchar(32) not null,"
        "   %s varchar(32) not null,"
        "   %s blob not null,"
        "   %s blob,"
        "   %s datetime not null,"
        "   primary key (%s), index (%s)"
        ");",
        RESTORE_ROLE_TABLE_NAME,    KG_ID_FIELD_NAME,         KG_NAME_FIELD_NAME, 
        KG_ACCOUNT_FIELD_NAME,      KG_BASE_INFO_FIELD_NAME,  KG_EXT_INFO_FIELD_NAME, 
        KG_DELETE_TIME_FIELD_NAME,  KG_ID_FIELD_NAME,         KG_ACCOUNT_FIELD_NAME
    );
    KGLOG_PROCESS_ERROR(nStrLen > 0 && nStrLen < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    if (!bRetCode)
    {
        KGLogPrintf(
            KGLOG_ERR, 
            "DB ERROR when try to create table \'%s\'\n", 
            RESTORE_ROLE_TABLE_NAME
        );
        goto Exit0;
    }

    nStrLen = snprintf(m_szSQL, sizeof(m_szSQL), 
        "create table if not exists %s "
        "("
        "   %s bigint not null auto_increment,"
        "   %s varchar(32) not null,"
        "   %s varchar(32) not null,"
        "   %s blob not null,"
        "   %s blob,"
        "   %s datetime not null,"
        "   primary key (%s), index (%s)"
        ");",
        DELETE_ROLE_TABLE_NAME,    KG_ID_FIELD_NAME,         KG_NAME_FIELD_NAME, 
        KG_ACCOUNT_FIELD_NAME,      KG_BASE_INFO_FIELD_NAME,  KG_EXT_INFO_FIELD_NAME, 
        KG_DELETE_TIME_FIELD_NAME,  KG_ID_FIELD_NAME,         KG_ACCOUNT_FIELD_NAME
        );
    KGLOG_PROCESS_ERROR(nStrLen > 0 && nStrLen < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    if (!bRetCode)
    {
        KGLogPrintf(
            KGLOG_ERR, 
            "DB ERROR when try to create table \'%s\'\n", 
            RESTORE_ROLE_TABLE_NAME
        );
        goto Exit0;
    }

    nResult = true;
Exit0:
    return nResult;
}
コード例 #3
0
ファイル: KSO3RoleDBTools.cpp プロジェクト: 1suming/pap2
int KSO3RoleDBTools::InsertMailBoxDateToNewDB(DWORD dwID)
{
    int             nResult            = false;
    int             nRetCode            = false;

    char*           pszPos              = NULL;
    size_t          uLeftBufferSize     = 0;
    unsigned long   ulLength            = 0;
    my_ulonglong    lAffectedRow        = 0;
    BYTE*           pbyExtInfo          = NULL;
    unsigned        uExtInfoDataLen     = 0;

    uLeftBufferSize = MAX_ROLE_DB_SQL_SIZE;

    memset(m_szSQL,0, sizeof(m_szSQL));
    pszPos = m_szSQL;

    nRetCode = snprintf(
        pszPos, uLeftBufferSize, "insert into %s (%s, %s, %s) "
        "values (%u, '",
        MAIL_TABLE_NAME, KG_ID_FIELD_NAME, MAIL_BASE_TIME_NAME, KG_MAIL_BOX_INFO_FIELD_NAME ,
        dwID
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    ulLength = (unsigned long)strlen(m_pSO3RoleDBUpdater->m_szMailBoxTime);
    KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);
    nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, m_pSO3RoleDBUpdater->m_szMailBoxTime, ulLength);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = snprintf(pszPos, uLeftBufferSize, "', '");
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    pbyExtInfo = (BYTE*)m_pSO3RoleDBUpdater->m_piMailBoxInfoPackage->GetData();
    nRetCode = m_pSO3RoleDBUpdater->GetMailBoxInfoSize(uExtInfoDataLen);
    KGLOG_PROCESS_ERROR(nRetCode);

    ulLength = (unsigned long)uExtInfoDataLen;
    KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);
    nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, (const char*)pbyExtInfo, uExtInfoDataLen);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = snprintf(pszPos, uLeftBufferSize, "');");
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = DoQuery(m_szSQL);
    if (!nRetCode) 
    {
        if (m_bConnected) // 执行失败的情况下且数据库连接没有断开
        {
            //nRetCode = eCreateRoleNameAlreadyExist;

        }
        goto Exit0;
    }

    lAffectedRow = mysql_affected_rows(m_pDBHandle);
    KGLOG_PROCESS_ERROR(lAffectedRow == 1);

    nResult = true;
Exit0:
    return nResult;
}
コード例 #4
0
ファイル: KSO3RoleDBTools.cpp プロジェクト: 1suming/pap2
int KSO3RoleDBTools::LoadMailBoxTable()
{
    BOOL                        bResult         = false;
    BOOL                        bRetCode        = false;
    int                         nRetCode        = false;
    MYSQL_RES*                  pQueryRes       = NULL;
    BYTE*                       pbyData         = NULL;
    unsigned long               ulDataSize       = 0;
    DWORD                       dwRoleCount     = 0;

    MYSQL_ROW                   QueryRow;

    ASSERT(m_pDBHandle);

    KGLogPrintf(KGLOG_INFO, "[DB] MailBox data loading ... ...");

    nRetCode = snprintf(
        m_szSQL, sizeof(m_szSQL), "select %s, %s, %s from %s", 
        KG_ID_FIELD_NAME, KG_MAIL_BOX_INFO_FIELD_NAME, MAIL_BASE_TIME_NAME, MAIL_TABLE_NAME
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    KGLOG_PROCESS_ERROR(bRetCode);

    pQueryRes = mysql_use_result(m_pDBHandle);
    KGLOG_PROCESS_ERROR(pQueryRes);

    KGLogPrintf(KGLOG_INFO, "Current [DB]'s MailBoxInfo Version Conver !Please do not close the application !!!!.....");

    while (true)
    {
        DWORD           dwRoleID    = ERROR_ID;
        unsigned long*  ulLengths   = NULL;

        QueryRow = mysql_fetch_row(pQueryRes);
        if (QueryRow == NULL)
        {
            goto Exit1;
        }

        ulLengths = mysql_fetch_lengths(pQueryRes);
        KGLOG_PROCESS_ERROR(ulLengths);

        ASSERT(QueryRow[0]);
        ASSERT(QueryRow[1]);
        ASSERT(QueryRow[2]);

        dwRoleID = (DWORD)strtoul(QueryRow[0], NULL, 10);

        pbyData = (BYTE*)QueryRow[1];
        ulDataSize = ulLengths[1];
        KGLOG_PROCESS_ERROR(ulDataSize <  MAIL_BOX_INFO_MAX_SIZE);

        strncpy(m_pSO3RoleDBUpdater->m_szMailBoxTime, QueryRow[2],sizeof(m_pSO3RoleDBUpdater->m_szMailBoxTime));
        m_pSO3RoleDBUpdater->m_szMailBoxTime[sizeof(m_pSO3RoleDBUpdater->m_szMailBoxTime) - 1] = '\0';

        nRetCode = m_pSO3RoleDBUpdater->ConverMailBoxInfo(dwRoleID, pbyData, ulDataSize);
        KGLOG_PROCESS_ERROR(nRetCode);


        nRetCode = m_pSO3RoleDBUpdater->InsertToNewDBMail(dwRoleID);
        KGLOG_PROCESS_ERROR(nRetCode);
        
        nRetCode = m_pSO3RoleDBUpdater->ResetMailBoxInfo();
        KGLOG_PROCESS_ERROR(nRetCode);

        ++dwRoleCount;
    }

Exit1:
    bResult = true;
Exit0:

    KGLogPrintf(KGLOG_INFO, "[DB] %u MailBoxInfo loaded !", dwRoleCount);

    if (pQueryRes)
    {
        mysql_free_result(pQueryRes);
        pQueryRes = NULL;
    }
    return bResult;
}
コード例 #5
0
ファイル: KSO3RoleDBTools.cpp プロジェクト: 1suming/pap2
int KSO3RoleDBTools::InsertRoleDateToNewDB(char szTableName[], char szTimeFileName[])
{
    int nResult = false;
    int nRetCode = false;

    char*           pszPos          = NULL;
    size_t          uLeftBufferSize = 0;
    unsigned long   ulLength        = 0;
    my_ulonglong    lAffectedRow    = 0;

    uLeftBufferSize = MAX_ROLE_DB_SQL_SIZE;

    memset(m_szSQL,0, sizeof(m_szSQL));
    pszPos = m_szSQL;

    nRetCode = snprintf(
        pszPos, uLeftBufferSize, "insert into %s (%s, %s, %s, %s, %s, %s) "
        "values (%u, '",
        szTableName, KG_ID_FIELD_NAME, szTimeFileName, KG_NAME_FIELD_NAME, KG_ACCOUNT_FIELD_NAME, 
        KG_BASE_INFO_FIELD_NAME, KG_EXT_INFO_FIELD_NAME,
        m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_dwRoleID
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    ulLength = (unsigned long)strlen(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleTime);
    KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);
    nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleTime, ulLength);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = snprintf(pszPos, uLeftBufferSize, "', '");
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    ulLength = (unsigned long)strlen(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleName);
    KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);
    nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleName, ulLength);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = snprintf(pszPos, uLeftBufferSize, "', '");
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    ulLength = (unsigned long)strlen(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szAccountName);
    KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);
    nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szAccountName, ulLength);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = snprintf(pszPos, uLeftBufferSize, "', '");
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    ulLength = (unsigned long)sizeof(KBaseInfo_Old);
    KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);
    nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, (const char*)&m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_BaseInfo, ulLength);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    if (m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_bHadExtInfo)
    {
        nRetCode = snprintf(pszPos, uLeftBufferSize, "', '");
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
        pszPos          += nRetCode;
        uLeftBufferSize -= nRetCode;

        BYTE*           pbyExtInfo          = NULL;
        unsigned        uExtInfoDataLen     = 0;
        pbyExtInfo = (BYTE*)m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_piPackage->GetData();
        uExtInfoDataLen = (unsigned int)m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_uPackageUseSize;

        nRetCode = CheckRoleDataCRC(pbyExtInfo, uExtInfoDataLen);
        KGLOG_PROCESS_ERROR(nRetCode);

        ulLength = (unsigned long)uExtInfoDataLen;
        KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);

        nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, (const char*)pbyExtInfo, ulLength);
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
        pszPos          += nRetCode;
        uLeftBufferSize -= nRetCode;

        nRetCode = snprintf(pszPos, uLeftBufferSize, "');");
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
        pszPos          += nRetCode;
        uLeftBufferSize -= nRetCode;
    }
    else
    {
        nRetCode = snprintf(pszPos, uLeftBufferSize, "', null);");
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
        pszPos          += nRetCode;
        uLeftBufferSize -= nRetCode;
    }

    nRetCode = DoQuery(m_szSQL);
    if (!nRetCode) 
    {
        if (m_bConnected) // 执行失败的情况下且数据库连接没有断开
        {
            //nRetCode = eCreateRoleNameAlreadyExist;
        }
        goto Exit0;
    }

    lAffectedRow = mysql_affected_rows(m_pDBHandle);
    KGLOG_PROCESS_ERROR(lAffectedRow == 1);

    nResult = true;
Exit0:
    return nResult;
}
コード例 #6
0
ファイル: KDBTools.cpp プロジェクト: viticm/pap2
int KDBTools::GetInfo(char szTableName[], char szGetFieldName[],
                      char szSearchFieldName[], char szSearchName[],
                      BYTE* pbyData, size_t uDataSize, size_t& uUseSize, int& nHadFind
)
{
    BOOL                        bResult         = false;
    BOOL                        bRetCode        = false;
    int                         nRetCode        = false;
    MYSQL_RES*                  pQueryRes       = NULL;
    MYSQL_ROW                   QueryRow;
    unsigned long*              pulLengths      = NULL;

    ASSERT(m_pDBHandle);
    ASSERT(szTableName);
    ASSERT(szGetFieldName);
    ASSERT(szSearchFieldName);
    ASSERT(szSearchName);
    ASSERT(pbyData);

    nRetCode = snprintf(
        m_szSQL, sizeof(m_szSQL), "select %s from %s where %s = \'%s\'", 
        szGetFieldName, szTableName, szSearchFieldName, szSearchName
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    KGLOG_PROCESS_ERROR(bRetCode);

    pQueryRes = mysql_use_result(m_pDBHandle);
    KGLOG_PROCESS_ERROR(pQueryRes);

    QueryRow = mysql_fetch_row(pQueryRes);
    if (QueryRow == NULL)
    {
        nHadFind = false;
        goto Exit1;
    }
    else
    {
        nHadFind = true;
    }

    pulLengths = mysql_fetch_lengths(pQueryRes);
    KGLOG_PROCESS_ERROR(pulLengths);

    uUseSize = pulLengths[0];
    KGLOG_PROCESS_ERROR(uDataSize >= uUseSize);

    memcpy(pbyData, QueryRow[0], uUseSize);

Exit1:
    bResult = true;
Exit0:

    if (pQueryRes)
    {
        mysql_free_result(pQueryRes);
        pQueryRes = NULL;
    }
    return bResult;
}
コード例 #7
0
ファイル: m_pgsql.cpp プロジェクト: thepaul/inspircd-deb
	bool DoConnectedPoll()
	{
		if(!qinprog && queue.totalsize())
		{
			/* There's no query currently in progress, and there's queries in the queue. */
			SQLrequest& query = queue.front();
			DoQuery(query);
		}

		if(PQconsumeInput(sql))
		{
			/* We just read stuff from the server, that counts as it being alive
			 * so update the idle-since time :p
			 */
			idle = this->ServerInstance->Time();

			if (PQisBusy(sql))
			{
				/* Nothing happens here */
			}
			else if (qinprog)
			{
				/* Grab the request we're processing */
				SQLrequest& query = queue.front();

				/* Get a pointer to the module we're about to return the result to */
				Module* to = query.GetSource();

				/* Fetch the result.. */
				PGresult* result = PQgetResult(sql);

				/* PgSQL would allow a query string to be sent which has multiple
				 * queries in it, this isn't portable across database backends and
				 * we don't want modules doing it. But just in case we make sure we
				 * drain any results there are and just use the last one.
				 * If the module devs are behaving there will only be one result.
				 */
				while (PGresult* temp = PQgetResult(sql))
				{
					PQclear(result);
					result = temp;
				}

				if(to)
				{
					/* ..and the result */
					PgSQLresult reply(us, to, query.id, result);

					/* Fix by brain, make sure the original query gets sent back in the reply */
					reply.query = query.query.q;

					switch(PQresultStatus(result))
					{
						case PGRES_EMPTY_QUERY:
						case PGRES_BAD_RESPONSE:
						case PGRES_FATAL_ERROR:
							reply.error.Id(SQL_QREPLY_FAIL);
							reply.error.Str(PQresultErrorMessage(result));
						default:
							;
							/* No action, other values are not errors */
					}

					reply.Send();

					/* PgSQLresult's destructor will free the PGresult */
				}
				else
				{
					/* If the client module is unloaded partway through a query then the provider will set
					 * the pointer to NULL. We cannot just cancel the query as the result will still come
					 * through at some point...and it could get messy if we play with invalid pointers...
					 */
					PQclear(result);
				}
				qinprog = false;
				queue.pop();
				DoConnectedPoll();
			}
			return true;
		}
		else
		{
			/* I think we'll assume this means the server died...it might not,
			 * but I think that any error serious enough we actually get here
			 * deserves to reconnect [/excuse]
			 * Returning true so the core doesn't try and close the connection.
			 */
			DelayReconnect();
			return true;
		}
	}
コード例 #8
0
ファイル: SmallTypeUnit.cpp プロジェクト: 25311753/asi
void __fastcall TSmallTypeForm::btnokClick(TObject *Sender)
{
   if (!dm1->ConnectDB())
      return;
   switch(btnidx)
   {
      case 0://do add
           if (!CheckEdit())
              break;
           if (!CheckCode())
              break;
           strsql =AnsiString("select st_code from dicsmalltype where st_code='")
                  +edtcode->Text+"'";
           if (DoQuery(dm1->Query1,strsql))
           {
              if (!dm1->Query1->IsEmpty())
              {
                 ErrorDlg("输入了重复的代码!");
                 break;
              }
           }
           else
           {
              SetButton(1,1,1,1,0,0,1,1);
              break;
           }
           strsql =AnsiString("insert into dicsmalltype values('")+edtcode->Text+"','"
                  +edtname->Text+"')";
           if (DoQuery(dm1->Query1,strsql,1))
           {
              btnref->Click();
              ClearEdit();
              edtcode->SetFocus();
           }
           break;
      case 1:
           LocateRow();
           break;
      case 2://do modify
           if (ListView1->SelCount==0)
           {
              InfoDlg("请先在列表中选择要修改的项次!");
              break;
           }
           if (!CheckEdit())
              break;
           if (!CheckCode())
              break;
           strsql =AnsiString("update dicsmalltype set st_name='")
                  +edtname->Text+"' where st_code='"
                  +ListView1->Selected->SubItems->Strings[0]+"'";
           if (DoQuery(dm1->Query1,strsql,1))
           {
              btnref->Click();
              ClearEdit();
              InfoDlg("修改完成!");
           }
           else
              SetButton(1,1,1,1,0,0,1,1);
           break;
      case 3://do delete
           if (ListView1->SelCount==0)
           {
              InfoDlg("请先在列表中选择要删除的项次!");
              break;
           }
           if (AskDlg("确实要删除该项次吗?")==IDNO)
              break;
           strsql =AnsiString("delete dicsmalltype where st_code='")
                  +ListView1->Selected->SubItems->Strings[0]+"'";
           if (DoQuery(dm1->Query1,strsql,1))
           {
              ClearEdit();
              btnref->Click();
              InfoDlg("删除完成!");
           }
           else
              SetButton(1,1,1,1,0,0,1,1);
           break;
   }
   dm1->db1->Connected=false;
}
コード例 #9
0
ファイル: main.c プロジェクト: aleksey-novikov/pbis
int main(
    int argc,
    char* argv[]
    )
{
    LWException *exc = NULL;
    int columns;
    PSTR pszLogFilePath = NULL;
    BOOLEAN bNoLog = FALSE;
    PSTR logLevel = "warning";
    DWORD dwLogLevel;
    BOOLEAN showHelp = FALSE;
    BOOLEAN showInternalHelp = FALSE;
    int remainingArgs = argc;
    char **argPos = argv;
    int i;
    BOOLEAN directoryExists = FALSE;

    if(CTGetTerminalWidth(fileno(stdout), &columns))
        columns = -1;

    /* Skip the program name */
    argPos++;
    remainingArgs--;

    setlocale(LC_ALL, "");

    while(remainingArgs > 0 && CTStrStartsWith(argPos[0], "--"))
    {
        if(!strcmp(argPos[0], "--help"))
            showHelp = TRUE;
        else if(!strcmp(argPos[0], "--help-internal"))
            showInternalHelp = TRUE;
        else if(!strcmp(argPos[0], "--nolog"))
            bNoLog = TRUE;
        //All options after this point take an argument
        else if(remainingArgs < 2)
            showHelp = TRUE;
        else if(!strcmp(argPos[0], "--logfile"))
        {
            pszLogFilePath = (++argPos)[0];
            remainingArgs--;
        }
        else if(!strcmp(argPos[0], "--loglevel"))
        {
            logLevel = (++argPos)[0];
            remainingArgs--;
        }
        else
            break;
        remainingArgs--;
        argPos++;
    }

    if(remainingArgs < 1)
        showHelp = TRUE;

    if (showInternalHelp) {
        ShowUsageInternal();
        goto cleanup;
    }

    if (showHelp) {
        ShowUsage();
        goto cleanup;
    }

    if (!strcasecmp(logLevel, "error"))
    {
        dwLogLevel = LOG_LEVEL_ERROR;
        LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_ERROR);
    }
    else if (!strcasecmp(logLevel, "warning"))
    {
        dwLogLevel = LOG_LEVEL_WARNING;
        LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_WARNING);
    }
    else if (!strcasecmp(logLevel, "info"))
    {
        dwLogLevel = LOG_LEVEL_INFO;
        LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_INFO);
    }
    else if (!strcasecmp(logLevel, "verbose"))
    {
        dwLogLevel = LOG_LEVEL_VERBOSE;
        LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_VERBOSE);
    }
    else if (!strcasecmp(logLevel, "debug"))
    {
        dwLogLevel = LOG_LEVEL_VERBOSE;
        LwRtlLogSetLevel(LW_RTL_LOG_LEVEL_DEBUG);
    }
    else {
        LW_CLEANUP_CTERR(&exc, LW_ERROR_INVALID_LOG_LEVEL);
    }

    if (pszLogFilePath == NULL)
    {
        // Determine the default log path
        LW_CLEANUP_CTERR(&exc,
                CTCheckDirectoryExists("/var/log", &directoryExists));
        if (directoryExists)
        {
            pszLogFilePath = "/var/log/domainjoin-cli.log";
        }
        else
        {
            pszLogFilePath = "/var/adm/domainjoin-cli.log";
        }
    }

    if (bNoLog) {
        LW_CLEANUP_CTERR(&exc, dj_disable_logging());
    } else if (!strcmp(pszLogFilePath, ".")) {
        LW_CLEANUP_CTERR(&exc, dj_init_logging_to_console(dwLogLevel));
    } else {
        DWORD ceError = dj_init_logging_to_file(dwLogLevel, pszLogFilePath);
        if(ceError == ERROR_ACCESS_DENIED)
        {
            fprintf(stderr, "Warning: insufficient permissions to log to %s. To enable logging, please specify a different filename with --logfile <file>.\n",
                    pszLogFilePath);
            ceError = ERROR_SUCCESS;
            LW_CLEANUP_CTERR(&exc, dj_disable_logging());
        }
        else if (ceError == ERROR_FILE_NOT_FOUND)
        {
            fprintf(stderr, "Warning: parent directory of log file %s does not exist. To enable logging, please specify a different filename with --logfile <file>.\n",
                    pszLogFilePath);
            ceError = ERROR_SUCCESS;
            LW_CLEANUP_CTERR(&exc, dj_disable_logging());
        }
        LW_CLEANUP_CTERR(&exc, ceError);
    }
    LwRtlLogSetCallback(RtlLogCallback, NULL);

    if (!strcmp(argPos[0], "join") || !strcmp(argPos[0], "leave"))
    {
        DJ_LOG_INFO("Domainjoin invoked with the %s command (remaining arguments will be printed later):", argPos[0]);
        // Only print up to the 'join' part
        for (i = 0; i <= argPos - argv; i++)
        {
            DJ_LOG_INFO("    [%s]", argv[i]);
        }
    }
    else
    {
        DJ_LOG_INFO("Domainjoin invoked with %d arg(s):", argc);
        for (i = 0; i < argc; i++)
        {
            DJ_LOG_INFO("    [%s]", argv[i]);
        }
    }

    if(!strcmp(argPos[0], "setname"))
    {
        PSTR pDomainSuffix = 0;
        argPos++;
        if(--remainingArgs != 1)
        {
            ShowUsage();
            goto cleanup;
        }

        pDomainSuffix = strchr(argPos[0], '.');
        if (pDomainSuffix)
        {
            *pDomainSuffix = 0;
            pDomainSuffix++;
        }
        else
        {
            pDomainSuffix = "";
        }
        LW_TRY(&exc, DJSetComputerName(argPos[0], pDomainSuffix, &LW_EXC));
    }
    else if(!strcmp(argPos[0], "join"))
    {
        argPos++;
        remainingArgs--;
        LW_TRY(&exc, DoJoin(remainingArgs, argPos, columns, &LW_EXC));
    }
    else if(!strcmp(argPos[0], "leave"))
    {
        argPos++;
        remainingArgs--;
        LW_TRY(&exc, DoLeaveNew(remainingArgs, argPos, columns, &LW_EXC));
    }
    else if(!strcmp(argPos[0], "query"))
    {
        LW_TRY(&exc, DoQuery(&LW_EXC));
    }
    else if(!strcmp(argPos[0], "fixfqdn"))
        LW_TRY(&exc, DoFixFqdn(&LW_EXC));
#ifndef ENABLE_MINIMAL
    else if(!strcmp(argPos[0], "configure"))
    {
        argPos++;
        remainingArgs--;
        LW_TRY(&exc, DoConfigure(remainingArgs, argPos, &LW_EXC));
    }
#endif
    else if(!strcmp(argPos[0], "get_os_type") ||
        !strcmp(argPos[0], "get_arch") ||
        !strcmp(argPos[0], "get_distro") ||
        !strcmp(argPos[0], "get_distro_version"))
    {
        LW_TRY(&exc, DoGetDistroInfo(remainingArgs, argPos, &LW_EXC));
    }
    else
    {
        LW_RAISE(&exc, LW_ERROR_SHOW_USAGE);
        goto cleanup;
    }

cleanup:

    if (!LW_IS_OK(exc) && exc->code == LW_ERROR_SHOW_USAGE)
    {
        ShowUsage();
        LWHandle(&exc);
    }
    else if (!LW_IS_OK(exc))
    {
        //Ignoring the return value from this because we can't do anything
        //if there is an error
        fprintf(stdout, "\n");
        LWPrintException(stdout, exc, FALSE);
        DJLogException(LOG_LEVEL_ERROR, exc);
        LWHandle(&exc);
        dj_close_log();
        return 1;
    }

    dj_close_log();

    return 0;
}
コード例 #10
0
void DoQueryNoRes (char const * const query) {
    MYSQL_RES * res = DoQuery(query);
    mysql_free_result(res);
}
コード例 #11
0
ファイル: gbseqget.c プロジェクト: hsptools/hsp-wrap
Int2 Main (void)

{
  AsnIoPtr    aip;
  AsnTypePtr  atp;
  FILE        *dfp = NULL;
  Boolean     do_nuc = FALSE;
  Boolean     do_prot = FALSE;
  XtraPtr     extra;
  FILE        *fp;
  GBSeq       gbsq;
  GBSet       gbst;
  Boolean     get_var;
  Char        line [256];
  Boolean     only_new;
  CharPtr     str;
  Char        xmlbuf [128];
  XtraBlock   xtra;

  ErrSetFatalLevel (SEV_MAX);
  ErrClearOptFlags (EO_SHOW_USERSTR);
  UseLocalAsnloadDataAndErrMsg ();
  ErrPathReset ();

  if (! AllObjLoad ()) {
    Message (MSG_FATAL, "AllObjLoad failed");
    return 1;
  }
  if (! SubmitAsnLoad ()) {
    Message (MSG_FATAL, "SubmitAsnLoad failed");
    return 1;
  }
  if (! SeqCodeSetLoad ()) {
    Message (MSG_FATAL, "SeqCodeSetLoad failed");
    return 1;
  }
  if (! GeneticCodeTableLoad ()) {
    Message (MSG_FATAL, "GeneticCodeTableLoad failed");
    return 1;
  }
  if (! objgbseqAsnLoad ()) {
    Message (MSG_POSTERR, "objgbseqAsnLoad failed");
    return 1;
  }

  if (! GetArgs ("gbseqget", sizeof (myargs) / sizeof (Args), myargs)) {
    return 0;
  }

  fp = FileOpen (myargs [i_argInputFile].strvalue, "r");
  if (fp == NULL) {
    return 1;
  }

  if (! StringHasNoText (myargs [d_argDateFile].strvalue)) {
    dfp = FileOpen (myargs [d_argDateFile].strvalue, "r");
    if (dfp == NULL) {
      return 1;
    }
  }

  if (GetAppParam ("NCBI", "SETTINGS", "XMLPREFIX", NULL, xmlbuf, sizeof (xmlbuf))) {
    AsnSetXMLmodulePrefix (StringSave (xmlbuf));
  }

  MemSet ((Pointer) &xtra, 0, sizeof (XtraBlock));
  MemSet ((Pointer) &gbsq, 0, sizeof (GBSeq));
  xtra.gbseq = &gbsq;
  aip = AsnIoOpen (myargs [o_argOutputFile].strvalue, "wx");

  if (aip == NULL) {
    Message (MSG_POSTERR, "AsnIoOpen failed");
    FileClose (fp);
    return 1;
  }

  only_new = (Boolean) myargs [n_argNewRecords].intvalue;
  get_var = (Boolean) myargs [v_argVariations].intvalue;

  str = myargs [m_argMolecule].strvalue;
  if (StringICmp (str, "n") == 0) {
    do_nuc = TRUE;
  } else if (StringICmp (str, "p") == 0) {
    do_prot = TRUE;
  } else if (StringICmp (str, "b") == 0) {
    do_nuc = TRUE;
    do_prot = TRUE;
  } else {
    do_nuc = TRUE;
  }

  PubSeqFetchEnable ();

  xtra.aip = aip;
  atp = AsnLinkType (NULL, AsnFind ("GBSet"));
  xtra.atp = AsnLinkType (NULL, AsnFind ("GBSet.E"));
  if (atp == NULL || xtra.atp == NULL) {
    Message (MSG_POSTERR, "AsnLinkType or AsnFind failed");
    return 1;
  }
  extra = &xtra;
  MemSet ((Pointer) &gbst, 0, sizeof (GBSet));
  AsnOpenStruct (aip, atp, (Pointer) &gbst);

  if (dfp != NULL) {
    DoQuery (fp, dfp, extra, get_var, do_nuc, do_prot);
  } else {
    str = ReadALine (line, sizeof (line), fp);
    while (str != NULL) {
      if (! StringHasNoText (str)) {
        ProcessAccession (str, extra, only_new, get_var, do_nuc, do_prot);
      }
      str = ReadALine (line, sizeof (line), fp);
    }
  }

  AsnCloseStruct (aip, atp, NULL);
  AsnPrintNewLine (aip);
  AsnIoClose (aip);

  FileClose (dfp);
  FileClose (fp);

  PubSeqFetchDisable ();

  return 0;
}
コード例 #12
0
ファイル: KIDSequence.cpp プロジェクト: viticm/pap2
BOOL KIDSequence::GenerateID(const char cszSequenceName[], int nPrefetch, uint64_t* puRetID)
{
    BOOL                                            bResult     = false;    
    int                                             nRetCode    = false;
    KID_PREFETCH_INFO*                              pPrefetch   = NULL;
    MYSQL_RES*                                      pQueryRes   = NULL;
    uint64_t                                        uStartID    = 0;
    my_ulonglong                                    uRowCount   = 0;
    MYSQL_ROW                                       Row;
    char                                            szQuery[256];
    KID_PREFETCH_TABLE::iterator                    it;
    std::pair<KID_PREFETCH_TABLE::iterator, BOOL>   InsRet;

    assert(cszSequenceName);
    assert(puRetID);
    assert(m_pDBHandle);
    assert(nPrefetch >= 1);

    m_Mutex.Lock();
    
    it = m_PrefetchTable.find(cszSequenceName);
    if (it != m_PrefetchTable.end())
    {
        pPrefetch = &it->second;
    }
    else
    {
        InsRet = m_PrefetchTable.insert(std::make_pair(cszSequenceName, KID_PREFETCH_INFO()));
        KGLOG_PROCESS_ERROR(InsRet.second);
        
        pPrefetch = &InsRet.first->second;

        pPrefetch->uIDEnd   = 0;
        pPrefetch->uNextID  = 0;
    }

    if (pPrefetch->uNextID < pPrefetch->uIDEnd)
        goto Exit1;

    while(true)
    { 
        nRetCode = snprintf(
            szQuery,  
            sizeof(szQuery),
            "select %s from %s where %s = '%s'",
            SEQ_CURRENT_ID, SEQ_TABLE_NAME, SEQ_NAME,
            cszSequenceName
        );
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(szQuery));

        nRetCode = DoQuery(szQuery);
        KGLOG_PROCESS_ERROR(nRetCode);

        if (pQueryRes)
        {
            mysql_free_result(pQueryRes);
            pQueryRes = NULL;
        }

        pQueryRes = mysql_store_result(m_pDBHandle);
        KGLOG_PROCESS_ERROR(pQueryRes);

        uRowCount = mysql_num_rows(pQueryRes);
        if (uRowCount == 0)
        {
            nRetCode = snprintf(
                szQuery, sizeof(szQuery),
                "insert into %s (%s, %s) values('%s', 1)",
                SEQ_TABLE_NAME, SEQ_NAME, SEQ_CURRENT_ID,
                cszSequenceName
            );
            KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(szQuery));

            nRetCode = DoQuery(szQuery);
            KGLOG_PROCESS_ERROR(nRetCode);

            continue;
        }

        Row = mysql_fetch_row(pQueryRes);
        KGLOG_PROCESS_ERROR(Row);
        
        assert(Row[0]);

        uStartID = (uint64_t)strtoull(Row[0], NULL, 10);
        
        KGLOG_PROCESS_ERROR(uStartID < ULLONG_MAX - nPrefetch);

        nRetCode = snprintf(
            szQuery,
            sizeof(szQuery),
            "update %s set %s = %s + %d where %s = '%s' and %s = %llu",
            SEQ_TABLE_NAME, SEQ_CURRENT_ID, SEQ_CURRENT_ID, nPrefetch,
            SEQ_NAME, cszSequenceName, SEQ_CURRENT_ID, uStartID
        );
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(szQuery));

        nRetCode = DoQuery(szQuery);
        KGLOG_PROCESS_ERROR(nRetCode);

        nRetCode = (int)mysql_affected_rows(m_pDBHandle);
        if (nRetCode == 1)
            break;
    }
    
    pPrefetch->uIDEnd   = uStartID + nPrefetch;
    pPrefetch->uNextID  = uStartID;

Exit1:
    *puRetID = pPrefetch->uNextID++;

    bResult = true;
Exit0:
    if (pQueryRes)
    {
        mysql_free_result(pQueryRes);
        pQueryRes = NULL;
    }

    m_Mutex.Unlock();
    return bResult;
}
コード例 #13
0
ファイル: KDBTools.cpp プロジェクト: viticm/pap2
int KDBTools::InsertNewRecord(const char cszTableName[], const FIELD_NAME_VECTOR& crFieldNameVector, const FIELD_INFO_VECTOR& crFieldInfoVector, int& rnSucceed)
{
    int nResult  = false;
    int nRetCode = false;

    char*           pszPos          = NULL;
    size_t          uLeftBufferSize = 0;
    unsigned long   ulLength        = 0;
    my_ulonglong    lAffectedRow    = 0;
    unsigned        uFieldCount     = 0;
    //unsigned        uDataLength     = 0;

    uLeftBufferSize = MAX_ROLE_DB_SQL_SIZE;

    KGLOG_PROCESS_ERROR(cszTableName);
    KGLOG_PROCESS_ERROR(cszTableName[0]);

    KGLOG_PROCESS_ERROR(crFieldNameVector.size() == crFieldInfoVector.size());

    memset(m_szSQL,0, sizeof(m_szSQL));
    pszPos = m_szSQL;

    nRetCode = snprintf(
        pszPos, uLeftBufferSize, "insert into `%s` (",
        cszTableName
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    uFieldCount = (unsigned)crFieldNameVector.size();
    KGLOG_PROCESS_ERROR(uFieldCount);
    for (unsigned i = 0; i < uFieldCount; i++)
    {
        if (i > 0)
        {
            nRetCode = snprintf(
                pszPos, uLeftBufferSize,
                " , "
            );
            KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
            pszPos          += nRetCode;
            uLeftBufferSize -= nRetCode;
        }

        nRetCode = snprintf(
            pszPos, uLeftBufferSize,
            "`%s`", crFieldNameVector[i].c_str()
        );
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
        pszPos          += nRetCode;
        uLeftBufferSize -= nRetCode;
    }

    nRetCode = snprintf(
        pszPos, uLeftBufferSize,
        ") values ('"
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    for (unsigned i = 0; i < uFieldCount; i++)
    {
        if (i > 0)
        {
            nRetCode = snprintf(
                pszPos, uLeftBufferSize,
                ", '"
            );
            KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
            pszPos          += nRetCode;
            uLeftBufferSize -= nRetCode;
        }

        ulLength = (unsigned long)crFieldInfoVector[i].uDataSize;
        KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);

        nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, (const char*)crFieldInfoVector[i].pvData, ulLength);
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
        pszPos          += nRetCode;
        uLeftBufferSize -= nRetCode;

        nRetCode = snprintf(pszPos, uLeftBufferSize, "' ");
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
        pszPos          += nRetCode;
        uLeftBufferSize -= nRetCode;
    }

    nRetCode = snprintf(
        pszPos, uLeftBufferSize,
        ");"
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    rnSucceed = false;
    nRetCode = DoQuery(m_szSQL);
    if (!nRetCode) 
    {
        if (m_bConnected) // 执行失败的情况下且数据库连接没有断开
        {
            //nRetCode = eCreateRoleNameAlreadyExist;

        }
        goto Exit0;
    }

    lAffectedRow = mysql_affected_rows(m_pDBHandle);
    KGLOG_PROCESS_ERROR(lAffectedRow == 1);

    rnSucceed = true;
    nResult = true;
Exit0:
    return nResult;
}
コード例 #14
0
ファイル: KDBTools.cpp プロジェクト: viticm/pap2
int KDBTools::UpDateField(char szTableName[], char szUpdateFieldName[], 
                          unsigned char* ucUpdateData, unsigned int unUndateDataSize,
                          char szSearchFieldName[], char szSearchName[],
                          int& nHadFind
)
{    
    int nResult  = false;
    int nRetCode = false;

    char*           pszPos          = NULL;
    size_t          uLeftBufferSize = 0;
    unsigned long   ulLength        = 0;
    my_ulonglong    lAffectedRow    = 0;

    uLeftBufferSize = MAX_ROLE_DB_SQL_SIZE;

    memset(m_szSQL,0, sizeof(m_szSQL));
    pszPos = m_szSQL;

    nRetCode = snprintf(
        pszPos, uLeftBufferSize, "update %s set %s = '",
        szTableName, szUpdateFieldName
    );

    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    ulLength = (unsigned long)unUndateDataSize;
    KGLOG_PROCESS_ERROR(uLeftBufferSize > ulLength * 2);

    nRetCode = mysql_real_escape_string(m_pDBHandle, pszPos, (const char*)ucUpdateData, ulLength);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = snprintf(pszPos, uLeftBufferSize, "' ");
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);
    pszPos          += nRetCode;
    uLeftBufferSize -= nRetCode;

    nRetCode = snprintf(pszPos, uLeftBufferSize, " where %s = `%s` ", szSearchFieldName, szSearchName);
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)uLeftBufferSize);

    nRetCode = DoQuery(m_szSQL);
    if (!nRetCode) 
    {
        if (m_bConnected) // 执行失败的情况下且数据库连接没有断开
        {
            //nRetCode = eCreateRoleNameAlreadyExist;
        }
        goto Exit0;
    }

    lAffectedRow = mysql_affected_rows(m_pDBHandle);
    KGLOG_PROCESS_ERROR(lAffectedRow <= 1);

    nResult = true;
Exit0:
    return nResult;
}
コード例 #15
0
ファイル: KSO3RoleDBTools.cpp プロジェクト: 1suming/pap2
int KSO3RoleDBTools::LoadAndCompareTable(char szTableName[], char szTimeFileName[])
{
    BOOL                        bResult         = false;
    BOOL                        bRetCode        = false;
    int                         nRetCode        = false;
    MYSQL_RES*                  pQueryRes       = NULL;
    DWORD                       dwRoleCount     = 0;
    KBaseInfo_Old*              pBaseInfo       = NULL;
    MYSQL_ROW                   QueryRow;

    ASSERT(m_pDBHandle);
    ASSERT(szTableName);

    KGLogPrintf(KGLOG_INFO, "[DB] %s Data loading ... ...", szTableName);

    nRetCode = snprintf(
        m_szSQL, sizeof(m_szSQL), "select %s, %s, %s, %s, %s, %s from %s", 
        KG_ID_FIELD_NAME,           KG_NAME_FIELD_NAME,     KG_ACCOUNT_FIELD_NAME, 
        KG_BASE_INFO_FIELD_NAME,    KG_EXT_INFO_FIELD_NAME, szTimeFileName, szTableName
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    KGLOG_PROCESS_ERROR(bRetCode);

    pQueryRes = mysql_use_result(m_pDBHandle);
    KGLOG_PROCESS_ERROR(pQueryRes);

    KGLogPrintf(KGLOG_INFO, "Current [DB]'s RoleDBDate Compare! Please do not close the application !!!!.....");

    while (true)
    {
        DWORD           dwRoleID            = ERROR_ID;
        unsigned long*  pulLengths           = NULL;

        QueryRow = mysql_fetch_row(pQueryRes);
        if (QueryRow == NULL)
        {
            goto Exit1;
        }

        pulLengths = mysql_fetch_lengths(pQueryRes);
        KGLOG_PROCESS_ERROR(pulLengths);

        KGLOG_PROCESS_ERROR(pulLengths[1] < _NAME_LEN);
        KGLOG_PROCESS_ERROR(pulLengths[2] < _NAME_LEN);

        if (pulLengths[3] != sizeof(KBaseInfo_Old))
        {
            KGLogPrintf(KGLOG_INFO, "The RoleDBDate is not 11 Version, please Use The 11 version RoleDB!");
            KGLOG_PROCESS_ERROR(false);// 屏蔽转换一半继续转换的功能,如果转换失败在这,请要重新恢复数据库.
            m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_bHadUpdateBaseInfo = true;
        }

        ASSERT(QueryRow[0]);
        ASSERT(QueryRow[1]);
        ASSERT(QueryRow[2]);
        ASSERT(QueryRow[3]);
        ASSERT(QueryRow[5]);

        strncpy(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleName, QueryRow[1], sizeof(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleName));
        m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleName[sizeof(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szRoleName) - 1] = '\0';
        strncpy(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szAccountName, QueryRow[2], sizeof(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szAccountName));
        m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szAccountName[sizeof(m_pSO3RoleDBUpdater->m_SO3RoleAllInfo.m_szAccountName) - 1] = '\0';
        dwRoleID = (DWORD)strtoul(QueryRow[0], NULL, 10);

        pBaseInfo = (KBaseInfo_Old*)QueryRow[3];

        nRetCode = m_pSO3RoleDBUpdater->GetRoleAllInfoToCompare(
            (BYTE*)QueryRow[3], pulLengths[3],
            (BYTE*)QueryRow[4], pulLengths[4],
            szTableName, szTimeFileName, dwRoleID
        );
        KGLOG_PROCESS_ERROR(nRetCode);

        nRetCode = m_pSO3RoleDBUpdater->ResetRoleAllInfo();
        KGLOG_PROCESS_ERROR(nRetCode);

        ++dwRoleCount;
    }

Exit1:
    bResult = true;
Exit0:

    KGLogPrintf(KGLOG_INFO, "[DB] %s %u roles loaded !", szTableName, dwRoleCount);

    if (pQueryRes)
    {
        mysql_free_result(pQueryRes);
        pQueryRes = NULL;
    }
    return bResult;
}
コード例 #16
0
ファイル: Identify.c プロジェクト: Paxxi/mDNSResponder
mDNSexport int main(int argc, char **argv)
{
    const char *progname = strrchr(argv[0], '/') ? strrchr(argv[0], '/') + 1 : argv[0];
    int this_arg = 1;
    mStatus status;
    struct in_addr s4;
#if HAVE_IPV6
    struct in6_addr s6;
#endif
    char buffer[256];
    DNSQuestion q;

    if (argc < 2) goto usage;

    // Since this is a special command-line tool, we want LogMsg() errors to go to stderr, not syslog
    mDNS_DebugMode = mDNStrue;

    // Initialise the mDNS core.
    status = mDNS_Init(&mDNSStorage, &PlatformStorage,
                       gRRCache, RR_CACHE_SIZE,
                       mDNS_Init_DontAdvertiseLocalAddresses,
                       mDNS_Init_NoInitCallback, mDNS_Init_NoInitCallbackContext);
    if (status) { fprintf(stderr, "Daemon start: mDNS_Init failed %d\n", (int)status); return(status); }

    signal(SIGINT, HandleSIG);  // SIGINT is what you get for a Ctrl-C
    signal(SIGTERM, HandleSIG);

    while (this_arg < argc)
    {
        char *arg = argv[this_arg++];
        if (this_arg > 2) printf("\n");

        lastid = id = zeroID;
        hostaddr = target = zeroAddr;
        hostname[0] = hardware[0] = software[0] = 0;
        NumAddr = NumAAAA = NumHINFO = 0;

        if (inet_pton(AF_INET, arg, &s4) == 1)
        {
            mDNSu8 *p = (mDNSu8 *)&s4;
            // Note: This is reverse order compared to a normal dotted-decimal IP address, so we can't use our customary "%.4a" format code
            mDNS_snprintf(buffer, sizeof(buffer), "%d.%d.%d.%d.in-addr.arpa.", p[3], p[2], p[1], p[0]);
            printf("%s\n", buffer);
            target.type = mDNSAddrType_IPv4;
            target.ip.v4.NotAnInteger = s4.s_addr;
            DoQuery(&q, buffer, kDNSType_PTR, &target, NameCallback);
            if (StopNow == 2) break;
        }
#if HAVE_IPV6
        else if (inet_pton(AF_INET6, arg, &s6) == 1)
        {
            int i;
            mDNSu8 *p = (mDNSu8 *)&s6;
            for (i = 0; i < 16; i++)
            {
                static const char hexValues[] = "0123456789ABCDEF";
                buffer[i * 4    ] = hexValues[p[15-i] & 0x0F];
                buffer[i * 4 + 1] = '.';
                buffer[i * 4 + 2] = hexValues[p[15-i] >> 4];
                buffer[i * 4 + 3] = '.';
            }
            mDNS_snprintf(&buffer[64], sizeof(buffer)-64, "ip6.arpa.");
            target.type = mDNSAddrType_IPv6;
            mDNSPlatformMemCopy(&target.ip.v6, &s6, sizeof(target.ip.v6));
            DoQuery(&q, buffer, kDNSType_PTR, &target, NameCallback);
            if (StopNow == 2) break;
        }
#endif
        else
        {
            if (strlen(arg) >= sizeof(hostname))
コード例 #17
0
ファイル: m_pgsql.cpp プロジェクト: AliSharifi/inspircd
	void DoConnectedPoll()
	{
restart:
		while (qinprog.q.empty() && !queue.empty())
		{
			/* There's no query currently in progress, and there's queries in the queue. */
			DoQuery(queue.front());
			queue.pop_front();
		}

		if (PQconsumeInput(sql))
		{
			if (PQisBusy(sql))
			{
				/* Nothing happens here */
			}
			else if (qinprog.c)
			{
				/* Fetch the result.. */
				PGresult* result = PQgetResult(sql);

				/* PgSQL would allow a query string to be sent which has multiple
				 * queries in it, this isn't portable across database backends and
				 * we don't want modules doing it. But just in case we make sure we
				 * drain any results there are and just use the last one.
				 * If the module devs are behaving there will only be one result.
				 */
				while (PGresult* temp = PQgetResult(sql))
				{
					PQclear(result);
					result = temp;
				}

				/* ..and the result */
				PgSQLresult reply(result);
				switch(PQresultStatus(result))
				{
					case PGRES_EMPTY_QUERY:
					case PGRES_BAD_RESPONSE:
					case PGRES_FATAL_ERROR:
					{
						SQLerror err(SQL_QREPLY_FAIL, PQresultErrorMessage(result));
						qinprog.c->OnError(err);
						break;
					}
					default:
						/* Other values are not errors */
						qinprog.c->OnResult(reply);
				}

				delete qinprog.c;
				qinprog = QueueItem(NULL, "");
				goto restart;
			}
			else
			{
				qinprog.q.clear();
			}
		}
		else
		{
			/* I think we'll assume this means the server died...it might not,
			 * but I think that any error serious enough we actually get here
			 * deserves to reconnect [/excuse]
			 * Returning true so the core doesn't try and close the connection.
			 */
			DelayReconnect();
		}
	}
コード例 #18
0
ファイル: KDBTools.cpp プロジェクト: viticm/pap2
int KDBTools::DelInfoIfFind(char szTableName[], char szGetFieldName[],
                            char szSearchFieldName[], char szSearchName[],
                            int& nHadFind
                            )
{
    BOOL                        bResult         = false;
    BOOL                        bRetCode        = false;
    int                         nRetCode        = false;
    MYSQL_RES*                  pQueryRes       = NULL;
    MYSQL_ROW                   QueryRow;

    ASSERT(m_pDBHandle);
    ASSERT(szTableName);
    ASSERT(szGetFieldName);
    ASSERT(szSearchFieldName);
    ASSERT(szSearchName);

    nRetCode = snprintf(
        m_szSQL, sizeof(m_szSQL), "select %s from %s where %s = \'%s\'", 
        szGetFieldName, szTableName, szSearchFieldName, szSearchName
    );
    KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(m_szSQL));

    bRetCode = DoQuery(m_szSQL);
    KGLOG_PROCESS_ERROR(bRetCode);

    pQueryRes = mysql_use_result(m_pDBHandle);
    KGLOG_PROCESS_ERROR(pQueryRes);

    QueryRow = mysql_fetch_row(pQueryRes);
    if (QueryRow == NULL)
    {
        nHadFind = false;
        goto Exit1;
    }
    else
    {
        nHadFind = true;
    }

    if (nHadFind)
    {
        nRetCode = snprintf(
            m_szSQL, sizeof(m_szSQL), "DELETE * from %s where %s = \'%s\'", 
            szTableName, szSearchFieldName, szSearchName
            );
        KGLOG_PROCESS_ERROR(nRetCode > 0 && nRetCode < (int)sizeof(m_szSQL));

        bRetCode = DoQuery(m_szSQL);
        KGLOG_PROCESS_ERROR(bRetCode);

        pQueryRes = mysql_use_result(m_pDBHandle);
        KGLOG_PROCESS_ERROR(pQueryRes);
    }

Exit1:
    bResult = true;
Exit0:

    if (pQueryRes)
    {
        mysql_free_result(pQueryRes);
        pQueryRes = NULL;
    }
    return bResult;
}