本文整理汇总了C++中IBS::Reset方法的典型用法代码示例。如果您正苦于以下问题:C++ IBS::Reset方法的具体用法?C++ IBS::Reset怎么用?C++ IBS::Reset使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IBS
的用法示例。
在下文中一共展示了IBS::Reset方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Users
void DatabaseImpl::Users(std::vector<std::string>& users)
{
if (mHandle == 0)
throw LogicExceptionImpl("Database::Users", _("Database is not connected."));
char items[] = {isc_info_user_names,
isc_info_end};
IBS status;
RB result(8000);
status.Reset();
(*gds.Call()->m_database_info)(status.Self(), &mHandle, sizeof(items), items,
result.Size(), result.Self());
if (status.Errors())
{
status.Reset();
throw SQLExceptionImpl(status, "Database::Users", _("isc_database_info failed"));
}
users.clear();
char* p = result.Self();
while (*p == isc_info_user_names)
{
p += 3; // Get to the length byte (there are two undocumented bytes which we skip)
int len = (int)(*p);
++p; // Get to the first char of username
if (len != 0) users.push_back(std::string().append(p, len));
p += len; // Skip username
}
return;
}
示例2: Counts
void DatabaseImpl::Counts(int* Insert, int* Update, int* Delete,
int* ReadIdx, int* ReadSeq)
{
if (mHandle == 0)
throw LogicExceptionImpl("Database::Counts", _("Database is not connected."));
char items[] = {isc_info_insert_count,
isc_info_update_count,
isc_info_delete_count,
isc_info_read_idx_count,
isc_info_read_seq_count,
isc_info_end};
IBS status;
RB result(1024);
status.Reset();
(*gds.Call()->m_database_info)(status.Self(), &mHandle, sizeof(items), items,
result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Database::Counts", _("isc_database_info failed"));
if (Insert != 0) *Insert = result.GetCountValue(isc_info_insert_count);
if (Update != 0) *Update = result.GetCountValue(isc_info_update_count);
if (Delete != 0) *Delete = result.GetCountValue(isc_info_delete_count);
if (ReadIdx != 0) *ReadIdx = result.GetCountValue(isc_info_read_idx_count);
if (ReadSeq != 0) *ReadSeq = result.GetCountValue(isc_info_read_seq_count);
}
示例3: Wait
void ServiceImpl::Wait()
{
IBS status;
SPB spb;
RB result(1024);
std::string msg;
spb.Insert(isc_info_svc_line);
for (;;)
{
// Sleeps 1 millisecond upfront. This will release the remaining
// timeslot of the thread. Doing so will give a good chance for small
// services tasks to finish before we check if they are still running.
// The deal is to limit (in that particular case) the number of loops
// polling _service_query that will happen.
Sleep(1);
// _service_query will only block until a line of result is available
// (or until the end of the task if it does not report information)
(*gds.Call()->m_service_query)(status.Self(), &mHandle, 0, 0, 0,
spb.Size(), spb.Self(), result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "ServiceImpl::Wait", _("isc_service_query failed"));
// If message length is zero bytes, task is finished
if (result.GetString(isc_info_svc_line, msg) == 0) return;
status.Reset();
result.Reset();
}
}
示例4: CursorExecute
void StatementImpl::CursorExecute(const std::string& cursor, const std::string& sql)
{
if (cursor.empty())
throw LogicExceptionImpl("Statement::CursorExecute", _("Cursor name can't be 0."));
if (! sql.empty()) Prepare(sql);
if (mHandle == 0)
throw LogicExceptionImpl("Statement::CursorExecute", _("No statement has been prepared."));
if (mType != IBPP::stSelectUpdate)
throw LogicExceptionImpl("Statement::CursorExecute", _("Statement must be a SELECT FOR UPDATE."));
if (mOutRow == 0)
throw LogicExceptionImpl("Statement::CursorExecute", _("Statement would return no rows."));
// Check that a value has been set for each input parameter
if (mInRow != 0 && mInRow->MissingValues())
throw LogicExceptionImpl("Statement::CursorExecute",
_("All parameters must be specified."));
CursorFree(); // Free a previous 'cursor' if any
IBS status;
(*gds.Call()->m_dsql_execute)(status.Self(), mTransaction->GetHandlePtr(),
&mHandle, 1, mInRow == 0 ? 0 : mInRow->Self());
if (status.Errors())
{
//Close(); Commented because Execute error should not free the statement
std::string context = "Statement::CursorExecute( ";
context.append(mSql).append(" )");
throw SQLExceptionImpl(status, context.c_str(),
_("isc_dsql_execute failed"));
}
status.Reset();
(*gds.Call()->m_dsql_set_cursor_name)(status.Self(), &mHandle, const_cast<char*>(cursor.c_str()), 0);
if (status.Errors())
{
//Close(); Commented because Execute error should not free the statement
throw SQLExceptionImpl(status, "Statement::CursorExecute",
_("isc_dsql_set_cursor_name failed"));
}
mResultSetAvailable = true;
mCursorOpened = true;
}
示例5: Statistics
void DatabaseImpl::Statistics(int* Fetches, int* Marks, int* Reads, int* Writes)
{
if (mHandle == 0)
throw LogicExceptionImpl("Database::Statistics", _("Database is not connected."));
char items[] = {isc_info_fetches,
isc_info_marks,
isc_info_reads,
isc_info_writes,
isc_info_end};
IBS status;
RB result(128);
status.Reset();
(*gds.Call()->m_database_info)(status.Self(), &mHandle, sizeof(items), items,
result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Database::Statistics", _("isc_database_info failed"));
if (Fetches != 0) *Fetches = result.GetValue(isc_info_fetches);
if (Marks != 0) *Marks = result.GetValue(isc_info_marks);
if (Reads != 0) *Reads = result.GetValue(isc_info_reads);
if (Writes != 0) *Writes = result.GetValue(isc_info_writes);
}
示例6: Info
void DatabaseImpl::Info(int* ODSMajor, int* ODSMinor,
int* PageSize, int* Pages, int* Buffers, int* Sweep,
bool* Sync, bool* Reserve)
{
if (mHandle == 0)
throw LogicExceptionImpl("Database::Info", _("Database is not connected."));
char items[] = {isc_info_ods_version,
isc_info_ods_minor_version,
isc_info_page_size,
isc_info_allocation,
isc_info_num_buffers,
isc_info_sweep_interval,
isc_info_forced_writes,
isc_info_no_reserve,
isc_info_end};
IBS status;
RB result(256);
status.Reset();
(*gds.Call()->m_database_info)(status.Self(), &mHandle, sizeof(items), items,
result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Database::Info", _("isc_database_info failed"));
if (ODSMajor != 0) *ODSMajor = result.GetValue(isc_info_ods_version);
if (ODSMinor != 0) *ODSMinor = result.GetValue(isc_info_ods_minor_version);
if (PageSize != 0) *PageSize = result.GetValue(isc_info_page_size);
if (Pages != 0) *Pages = result.GetValue(isc_info_allocation);
if (Buffers != 0) *Buffers = result.GetValue(isc_info_num_buffers);
if (Sweep != 0) *Sweep = result.GetValue(isc_info_sweep_interval);
if (Sync != 0)
*Sync = result.GetValue(isc_info_forced_writes) == 1 ? true : false;
if (Reserve != 0)
*Reserve = result.GetValue(isc_info_no_reserve) == 1 ? false : true;
}
示例7: Prepare
void StatementImpl::Prepare(const std::string& sql)
{
if (mDatabase == 0)
throw LogicExceptionImpl("Statement::Prepare", _("An IDatabase must be attached."));
if (mDatabase->GetHandle() == 0)
throw LogicExceptionImpl("Statement::Prepare", _("IDatabase must be connected."));
if (mTransaction == 0)
throw LogicExceptionImpl("Statement::Prepare", _("An ITransaction must be attached."));
if (mTransaction->GetHandle() == 0)
throw LogicExceptionImpl("Statement::Prepare", _("ITransaction must be started."));
if (sql.empty())
throw LogicExceptionImpl("Statement::Prepare", _("SQL statement can't be 0."));
// Saves the SQL sentence, only for reporting reasons in case of errors
mSql = sql;
IBS status;
// Free all resources currently attached to this Statement, then allocate
// a new statement descriptor.
Close();
(*gds.Call()->m_dsql_allocate_statement)(status.Self(), mDatabase->GetHandlePtr(), &mHandle);
if (status.Errors())
throw SQLExceptionImpl(status, "Statement::Prepare",
_("isc_dsql_allocate_statement failed"));
// Empirical estimate of parameters count and output columns count.
// This is by far not an exact estimation, which would require parsing the
// SQL statement. If the SQL statement contains '?' and ',' in string
// constants, this count will obviously be wrong, but it will be exagerated.
// It won't hurt. We just try to not have to re-allocate those descriptors later.
// So we prefer to get them a little bit larger than needed than the other way.
int16_t inEstimate = 0;
int16_t outEstimate = 1;
for (size_t i = 0; i < strlen(sql.c_str()); i++)
{
if (sql[i] == '?') ++inEstimate;
if (sql[i] == ',') ++outEstimate;
}
/*
DebugStream()<< "Prepare(\""<< sql<< "\")"<< fds;
DebugStream()<< _("Estimation: ")<< inEstimate<< _(" IN parameters and ")
<< outEstimate<< _(" OUT columns")<< fds;
*/
// Allocates output descriptor and prepares the statement
mOutRow = new RowImpl(mDatabase->Dialect(), outEstimate, mDatabase, mTransaction);
mOutRow->AddRef();
status.Reset();
(*gds.Call()->m_dsql_prepare)(status.Self(), mTransaction->GetHandlePtr(),
&mHandle, (short)sql.length(), const_cast<char*>(sql.c_str()),
short(mDatabase->Dialect()), mOutRow->Self());
if (status.Errors())
{
Close();
std::string context = "Statement::Prepare( ";
context.append(mSql).append(" )");
throw SQLExceptionImpl(status, context.c_str(),
_("isc_dsql_prepare failed"));
}
// Read what kind of statement was prepared
status.Reset();
char itemsReq[] = {isc_info_sql_stmt_type};
char itemsRes[8];
(*gds.Call()->m_dsql_sql_info)(status.Self(), &mHandle, 1, itemsReq,
sizeof(itemsRes), itemsRes);
if (status.Errors())
{
Close();
throw SQLExceptionImpl(status, "Statement::Prepare",
_("isc_dsql_sql_info failed"));
}
if (itemsRes[0] == isc_info_sql_stmt_type)
{
switch (itemsRes[3])
{
case isc_info_sql_stmt_select : mType = IBPP::stSelect; break;
case isc_info_sql_stmt_insert : mType = IBPP::stInsert; break;
case isc_info_sql_stmt_update : mType = IBPP::stUpdate; break;
case isc_info_sql_stmt_delete : mType = IBPP::stDelete; break;
case isc_info_sql_stmt_ddl : mType = IBPP::stDDL; break;
case isc_info_sql_stmt_exec_procedure : mType = IBPP::stExecProcedure; break;
case isc_info_sql_stmt_select_for_upd : mType = IBPP::stSelectUpdate; break;
case isc_info_sql_stmt_set_generator : mType = IBPP::stSetGenerator; break;
case isc_info_sql_stmt_savepoint : mType = IBPP::stSavePoint; break;
default : mType = IBPP::stUnsupported;
}
}
if (mType == IBPP::stUnknown || mType == IBPP::stUnsupported)
{
Close();
throw LogicExceptionImpl("Statement::Prepare",
_("Unknown or unsupported statement type"));
}
if (mOutRow->Columns() == 0)
{
//.........这里部分代码省略.........
示例8: Connect
void DatabaseImpl::Connect()
{
if (mHandle != 0) return; // Already connected
if (mDatabaseName.empty())
throw LogicExceptionImpl("Database::Connect", _("Unspecified database name."));
if (mUserName.empty())
throw LogicExceptionImpl("Database::Connect", _("Unspecified user name."));
// Build a DPB based on the properties
DPB dpb;
dpb.Insert(isc_dpb_user_name, mUserName.c_str());
dpb.Insert(isc_dpb_password, mUserPassword.c_str());
if (! mRoleName.empty()) dpb.Insert(isc_dpb_sql_role_name, mRoleName.c_str());
if (! mCharSet.empty()) dpb.Insert(isc_dpb_lc_ctype, mCharSet.c_str());
std::string connect;
if (! mServerName.empty())
connect.assign(mServerName).append(":");
connect.append(mDatabaseName);
IBS status;
(*gds.Call()->m_attach_database)(status.Self(), (short)connect.size(),
const_cast<char*>(connect.c_str()), &mHandle, dpb.Size(), dpb.Self());
if (status.Errors())
{
mHandle = 0; // Should be, but better be sure...
throw SQLExceptionImpl(status, "Database::Connect", _("isc_attach_database failed"));
}
// Now, get ODS version information and dialect.
// If ODS major is lower of equal to 9, we reject the connection.
// If ODS major is 10 or higher, this is at least an InterBase 6.x Server
// OR FireBird 1.x Server.
char items[] = {isc_info_ods_version,
isc_info_db_SQL_dialect,
isc_info_end};
RB result(100);
status.Reset();
(*gds.Call()->m_database_info)(status.Self(), &mHandle, sizeof(items), items,
result.Size(), result.Self());
if (status.Errors())
{
status.Reset();
(*gds.Call()->m_detach_database)(status.Self(), &mHandle);
mHandle = 0; // Should be, but better be sure...
throw SQLExceptionImpl(status, "Database::Connect", _("isc_database_info failed"));
}
int ODS = result.GetValue(isc_info_ods_version);
if (ODS <= 9)
{
status.Reset();
(*gds.Call()->m_detach_database)(status.Self(), &mHandle);
mHandle = 0; // Should be, but better be sure...
throw LogicExceptionImpl("Database::Connect",
_("Unsupported Server : wrong ODS version (%d), at least '10' required."), ODS);
}
mDialect = result.GetValue(isc_info_db_SQL_dialect);
if (mDialect != 1 && mDialect != 3)
{
status.Reset();
(*gds.Call()->m_detach_database)(status.Self(), &mHandle);
mHandle = 0; // Should be, but better be sure...
throw LogicExceptionImpl("Database::Connect", _("Dialect 1 or 3 required"));
}
// Now, verify the GDS32.DLL we are using is compatible with the server
if (ODS >= 10 && gds.Call()->mGDSVersion < 60)
{
status.Reset();
(*gds.Call()->m_detach_database)(status.Self(), &mHandle);
mHandle = 0; // Should be, but better be sure...
throw LogicExceptionImpl("Database::Connect", _("GDS32.DLL version 5 against IBSERVER 6"));
}
}
示例9: GetUsers
void ServiceImpl::GetUsers(std::vector<IBPP::User>& users)
{
if (mHandle == 0)
throw LogicExceptionImpl("Service::GetUsers", _("Service is not connected."));
SPB spb;
spb.Insert(isc_action_svc_display_user);
IBS status;
(*gds.Call()->m_service_start)(status.Self(), &mHandle, 0, spb.Size(), spb.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::GetUsers", _("isc_service_start failed"));
RB result(0xFFFF);
char request[] = {isc_info_svc_get_users};
status.Reset();
(*gds.Call()->m_service_query)(status.Self(), &mHandle, 0, 0, 0,
sizeof(request), request, result.Size(), result.Self());
if (status.Errors())
throw SQLExceptionImpl(status, "Service::GetUsers", _("isc_service_query failed"));
users.clear();
char* p = result.Self();
if (*p != isc_info_svc_get_users)
throw SQLExceptionImpl(status, "Service::GetUsers", _("isc_service_query returned unexpected answer"));
char* pEnd = p + (unsigned short)(*gds.Call()->m_vax_integer)(p+1, 2);
p += 3; // Skips the 'isc_info_svc_get_users' and its total length
IBPP::User user;
while (p < pEnd && *p != isc_info_end)
{
if (*p == isc_spb_sec_userid)
{
user.userid = (uint32_t)(*gds.Call()->m_vax_integer)(p+1, 4);
p += 5;
}
else if (*p == isc_spb_sec_groupid)
{
user.groupid = (uint32_t)(*gds.Call()->m_vax_integer)(p+1, 4);
p += 5;
}
else
{
unsigned short len = (unsigned short)(*gds.Call()->m_vax_integer)(p+1, 2);
switch (*p)
{
case isc_spb_sec_username :
// For each user, this is the first element returned
if (! user.username.empty()) users.push_back(user); // Flush previous user
user.clear();
if (len != 0) user.username.assign(p+3, len);
break;
case isc_spb_sec_password :
if (len != 0) user.password.assign(p+3, len);
break;
case isc_spb_sec_firstname :
if (len != 0) user.firstname.assign(p+3, len);
break;
case isc_spb_sec_middlename :
if (len != 0) user.middlename.assign(p+3, len);
break;
case isc_spb_sec_lastname :
if (len != 0) user.lastname.assign(p+3, len);
break;
}
p += (3 + len);
}
}
if (! user.username.empty()) users.push_back(user); // Flush last user
}