SQL数据库丢了看代码可以重新建立吗?
里面有这些内容
BOOL CSQL::DBConnect(unsigned char * Server,unsigned char * User,unsigned char* Pass)
{
SQLRETURN ret;
ret = SQLAllocHandle (SQL_HANDLE_ENV, SQL_NULL_HANDLE, &g_henv); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) return FALSE;
ret = SQLSetEnvAttr (g_henv,SQL_ATTR_ODBC_VERSION,(void*)SQL_OV_ODBC3, 0); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) return FALSE;
ret = SQLAllocHandle (SQL_HANDLE_DBC, g_henv, &g_hdbc); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) return FALSE;
ret = SQLSetConnectAttr (g_hdbc,SQL_LOGIN_TIMEOUT,(SQLPOINTER)5, 0); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) return FALSE;
ret = SQLConnect (g_hdbc,Server,SQL_NTS,User,SQL_NTS,Pass,SQL_NTS); if (ret != SQL_SUCCESS && ret != SQL_SUCCESS_WITH_INFO) return FALSE;
return TRUE;
}
void CSQL::DBRelease()
{
if (g_hdbc) SQLDisconnect(g_hdbc);
if (g_hdbc) SQLFreeHandle(SQL_HANDLE_DBC, g_hdbc);
if (g_henv) SQLFreeHandle(SQL_HANDLE_ENV, g_henv);
if (g_hstmt) SQLFreeHandle(SQL_HANDLE_STMT, g_hstmt);
}
// szQuery = "select map_name map_info map_size init_money, need_money1, need_money2 from maplist order by map_name";
BOOL CSQL::ExecuteStart(char * szQuery)
{
SQLRETURN ret;
ret = SQLAllocHandle(SQL_HANDLE_STMT, g_hdbc, &g_hstmt); if (ret!=SQL_SUCCESS && ret!=SQL_SUCCESS_WITH_INFO) return FALSE;
ret = SQLPrepare(g_hstmt, (SQLCHAR*)szQuery, SQL_NTS); if ( ret!=SQL_SUCCESS && ret!=SQL_SUCCESS_WITH_INFO ) return FALSE;
ret = SQLExecute(g_hstmt); if ( ret!=SQL_SUCCESS && ret!=SQL_SUCCESS_WITH_INFO ) return FALSE;
return TRUE;
}
BOOL CSQL::GetStmt(void)
{ SQLRETURN ret;
ret = SQLAllocHandle(SQL_HANDLE_STMT, g_hdbc, &g_hstmt); if (ret!=SQL_SUCCESS && ret!=SQL_SUCCESS_WITH_INFO) return FALSE;
return TRUE;
}
BOOL CSQL::FreeStmt(void)
{ if (g_hstmt) SQLFreeHandle(SQL_HANDLE_STMT /*|SQL_RESET_PARAMS */, g_hstmt);
g_hstmt=NULL;
return TRUE;
}
BOOL CSQL::ExecuteEnd()
{ SQLFreeHandle(SQL_HANDLE_STMT, g_hstmt);
return TRUE;
}
...........................................