本文整理汇总了C++中Sql类的典型用法代码示例。如果您正苦于以下问题:C++ Sql类的具体用法?C++ Sql怎么用?C++ Sql使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Sql类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
void operator*=(ValueMap& map, SqlSelect select)
{
map.Clear();
Sql sql;
sql * select;
while(sql.Fetch())
map.Add(sql[0], sql[1]);
}
示例2: ASSERT
Value SqlStatement::Fetch(Sql& cursor) const {
ASSERT(text.GetCount());
if(!Execute(cursor))
return ErrorValue(SqlExc(cursor.GetSession()));
if(!cursor.Fetch())
return Null;
return cursor[0];
}
示例3: ForceInsertRowid
String ForceInsertRowid(const String& insert, Sql& cursor)
{
if(!cursor.Execute(insert + " returning ROWID into ?%s"))
throw SqlExc(cursor.GetSession());
if(!cursor.Fetch())
throw Exc(t_("FETCH internal error (ForceInsertRowid)"));
ASSERT(!IsNull(cursor[0]));
return cursor[0];
}
示例4: Describe
VectorMap<String, SqlColumnInfo> Describe(const SqlVal& table, Sql& cursor)
{
VectorMap<String, SqlColumnInfo> map;
if(cursor * SelectAll().From(table).Where(SqlBool::False()))
for(int i = 0, n = cursor.GetColumns(); i < n; i++)
{
const SqlColumnInfo& sci = cursor.GetColumnInfo(i);
map.Add(sci.name, sci);
}
return map;
}
示例5: SqlError
int SqlError(
#ifdef PLATFORM_WIN32
HWND parent,
#endif
const char *text, const Sql& sql, bool retry) {
return SqlError(
#ifdef PLATFORM_WIN32
parent,
#endif
text, sql.GetSession(), retry);
}
示例6: OkCommit
bool OkCommit(Sql& sql, const char *emsg) {
return OkCommit(sql.GetSession(), emsg);
}
示例7: ErrorRollback
bool ErrorRollback(Sql& sql, const char *emsg) {
return ErrorRollback(sql.GetSession(), emsg);
}
示例8: IsNotEmpty
bool IsNotEmpty(const SqlSelect& select, Sql& cursor)
{
return cursor * select && cursor.Fetch();
}
示例9: threadHandler
void threadHandler(char driveLtr)
{
/* Lock the mutex so we don't try and access the database at the same time */
gMutex.lock();
bool authorized = false;
/* Lock the USB drive */
UsbOps ops;
ops.lockUSB(driveLtr);
/* Query authorized devices */
Sql sql;
if (!sql.dbConnect((char*)Paths::getDatabasePath().c_str(), false))
{
ErrorLog::logErrorToFile("*CRITICAL*", "Unable to open authorized drives database!");
ops.ejectUSB();
gMutex.unlock();
return;
}
std::vector<authedDrive> drvs;
sql.queryAuthedDrives(&drvs);
/* Get the serial key of the device */
UsbKey usbKey;
UsbKeyhdr hdr;
ops.unlockUSB();
usbKey.getUsbKeyHdr(&hdr, driveLtr);
ops.lockUSB(driveLtr);
/* Check if the serial exists in the database */
for (std::vector<authedDrive>::iterator it = drvs.begin(); it != drvs.end(); it++)
{
std::cout << it->serial.c_str() << " " << hdr.serialkey.c_str() << std::endl;
if (it->serial.compare(hdr.serialkey) == 0)
{
authorized = true;
break;
}
}
ops.unlockUSB();
/* Log media insertion event */
AccessLog *log = new AccessLog();
log->createLogStruct(&log->logUSBStruct, driveLtr, (char*)hdr.serialkey.c_str());
log->logUSBStruct.accepted = authorized;
/* Get config settings, check if remote SQL is enabled */
ConfigParser configParser((char*)Paths::getConfigPath().c_str());
if (configParser.getValue("SQLenabled") == "1")
{
/* SQL enabled = true */
log->logUsbDrive(log->logUSBStruct, true);
}
else
log->logUsbDrive(log->logUSBStruct, false);
/* If not authorized, eject it! */
if (!authorized)
{
ops.lockUSB(driveLtr);
ops.ejectUSB();
}
/* Check for viruses here... */
gMutex.unlock();
delete log;
}
示例10: DisplayError
bool DisplayError(const Sql& sql, const char *msg) {
return DisplayError(sql.GetSession(), msg);
}
示例11: Title
void DlgSqlExport::Run(Sql& cursor, String command, String tablename)
{
Title(Nvl(tablename, t_("SQL query")) + t_(" export"));
object_name <<= tablename;
if(!cursor.Execute(command)) {
Exclamation(NFormat(t_("Error executing [* \1%s\1]: \1%s"), command, cursor.GetLastError()));
return;
}
for(int i = 0; i < cursor.GetColumns(); i++) {
const SqlColumnInfo& sci = cursor.GetColumnInfo(i);
String type;
switch(sci.valuetype) {
case BOOL_V:
case INT_V: type = t_("integer"); break;
case DOUBLE_V: type = t_("real number"); break;
case STRING_V:
case WSTRING_V: type = t_("string"); break;
case DATE_V: type = t_("date"); break;
case TIME_V: type = t_("date/time"); break;
case /*ORA_BLOB_V*/-1: type = t_("BLOB"); break;
case /*ORA_CLOB_V*/-2: type = t_("CLOB"); break;
default: type = FormatInt(sci.valuetype); break;
}
columns.Add(sci.name, sci.valuetype, sci.width, 1);
}
static String cfg;
LoadFromString(*this, cfg);
SyncUI();
while(TopWindow::Run() == IDOK)
try {
String out_table = ~object_name;
String delim;
switch((int)~delimiters) {
case DELIM_TAB: delim = "\t"; break;
case DELIM_SEMICOLON: delim = ";"; break;
}
Vector<int> out;
String colstr;
String title;
for(int i = 0; i < columns.GetCount(); i++)
if(columns.Get(i, 3)) {
out.Add(i);
String cname = cursor.GetColumnInfo(i).name;
colstr << (i ? ", " : "") << cname;
if(i) title << delim;
title << cname;
}
if(out.IsEmpty()) {
throw Exc(t_("No columns selected!"));
continue;
}
String rowbegin, rowend;
int fmt = ~format;
FileSel fsel;
String ext;
switch(fmt) {
case FMT_TEXT: {
rowend = "";
ext = ".txt";
fsel.Type(t_("Text files (*.txt)"), "*.txt");
break;
}
case FMT_SQL: {
if(identity_insert)
rowbegin << "set identity_insert " << out_table << " on ";
rowbegin << "insert into " << out_table << "(" << colstr << ") values (";
rowend = ");";
ext = ".sql";
fsel.Type(t_("SQL scripts (*.sql)"), "*.sql");
break;
}
}
fsel.AllFilesType().DefaultExt(ext.Mid(1));
if(!IsNull(recent_file))
fsel <<= ForceExt(recent_file, ext);
if(!fsel.ExecuteSaveAs(t_("Save export as")))
continue;
recent_file = ~fsel;
FileOut fo;
if(!fo.Open(recent_file)) {
Exclamation(NFormat(t_("Error creating file [* \1%s\1]."), recent_file));
continue;
}
if(fmt == FMT_TEXT)
fo.PutLine(title);
Progress progress(t_("Exporting row %d"));
while(cursor.Fetch()) {
String script = rowbegin;
for(int i = 0; i < out.GetCount(); i++) {
Value v = cursor[out[i]];
switch(fmt) {
case FMT_TEXT: {
if(i)
script.Cat(delim);
if(IsString(v) && quote) {
String s = v;
script << '\"';
for(const char *p = s, *e = s.End(); p < e; p++)
if(*p == '\"')
script.Cat("\"\"");
//.........这里部分代码省略.........
示例12: Attach
void SqlConnection::Attach(Sql& sql, SqlConnection *con)
{
sql.Attach(con); // Duck tape to fix Oci8
}
示例13: Exc
SqlExc::SqlExc(const Sql& sql) : Exc(sql_error) {
SetSessionError(sql.GetSession());
}
示例14: ShowError
bool ShowError(Sql& sql, const char *msg) {
return ShowError(sql.GetSession(), msg);
}
示例15: Execute
bool SqlStatement::Execute(Sql& cursor) const {
ASSERT(text.GetCount());
return cursor.Execute(*this);
}