本文整理汇总了C++中CppSQLite3Query::fieldDataType方法的典型用法代码示例。如果您正苦于以下问题:C++ CppSQLite3Query::fieldDataType方法的具体用法?C++ CppSQLite3Query::fieldDataType怎么用?C++ CppSQLite3Query::fieldDataType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CppSQLite3Query
的用法示例。
在下文中一共展示了CppSQLite3Query::fieldDataType方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
szDML = "delete from parts where no = 2;"
"delete from parts where no = 3;";
nRows = db.execDML(szDML);
cout << endl << nRows << " rows affected" << endl;
cout << db.execScalar("select count(*) from parts;") << " rows in parts table" << endl;
////////////////////////////////////////////////////////////////////////////////
// Demonstrate new typing system & BLOBS
// ANy data can be stored in any column
////////////////////////////////////////////////////////////////////////////////
cout << endl << "Data types and BLOBs()" << endl;
db.execDML("create table types(no int, "
"name char(20), qty float, dat blob);");
db.execDML("insert into types values(null, null, null, null);");
db.execDML("insert into types values(1, 2, 3, 4);");
db.execDML("insert into types values(1.1, 2.2, 3.3, 4.4);");
db.execDML("insert into types values('a', 'b', 'c', 'd');");
CppSQLite3Statement stmt = db.compileStatement("insert into types values(?,?,?,?);");
unsigned char buf[256];
memset(buf, 1, 1); stmt.bind(1, buf, 1);
memset(buf, 2, 2); stmt.bind(2, buf, 2);
memset(buf, 3, 3); stmt.bind(3, buf, 3);
memset(buf, 4, 4); stmt.bind(4, buf, 4);
stmt.execDML();
cout << db.execScalar("select count(*) from types;") << " rows in types table" << endl;
q = db.execQuery("select * from types;");
while (!q.eof())
{
for (int i = 0; i < q.numFields(); i++)
{
switch (q.fieldDataType(i))
{
case SQLITE_INTEGER : cout << "SQLITE_INTEGER|"; break;
case SQLITE_FLOAT : cout << "SQLITE_FLOAT |"; break;
case SQLITE_TEXT : cout << "SQLITE_TEXT |"; break;
case SQLITE_BLOB : cout << "SQLITE_BLOB |"; break;
case SQLITE_NULL : cout << "SQLITE_NULL |"; break;
default: cout << "***UNKNOWN TYPE***"; break;
}
}
q.nextRow();
cout << endl;
}
nRows = db.execDML("delete from types where no = 1 or no = 1.1 or no = 'a' or no is null;");
cout << endl << nRows << " rows deleted, leaving binary row only" << endl;
q = db.execQuery("select * from types;");
const unsigned char* pBlob;
int nLen;
pBlob = q.getBlobField(0, nLen);
cout << "Field 1 BLOB length: " << nLen << endl;
pBlob = q.getBlobField(1, nLen);
cout << "Field 2 BLOB length: " << nLen << endl;
pBlob = q.getBlobField(2, nLen);
cout << "Field 3 BLOB length: " << nLen << endl;
pBlob = q.getBlobField(3, nLen);
cout << "Field 4 BLOB length: " << nLen << endl;
q.finalize();
nRows = db.execDML("delete from types;");
cout << endl << nRows << " rows deleted, leaving empty table" << endl;
示例2: main
int main(int argc, char** argv)
{
try
{
int i, fld;
time_t tmStart, tmEnd;
CppSQLite3DB db;
cout << "SQLite Version: " << db.SQLiteVersion() << endl;
remove(gszFile);
db.open(gszFile);
cout << endl << "Creating emp table" << endl;
db.execDML("create table emp(empno int, empname char(20));");
///////////////////////////////////////////////////////////////
// Execute some DML, and print number of rows affected by each one
///////////////////////////////////////////////////////////////
cout << endl << "DML tests" << endl;
int nRows = db.execDML("insert into emp values (7, 'David Beckham');");
cout << nRows << " rows inserted" << endl;
nRows = db.execDML(
"update emp set empname = 'Christiano Ronaldo' where empno = 7;");
cout << nRows << " rows updated" << endl;
nRows = db.execDML("delete from emp where empno = 7;");
cout << nRows << " rows deleted" << endl;
/////////////////////////////////////////////////////////////////
// Transaction Demo
// The transaction could just as easily have been rolled back
/////////////////////////////////////////////////////////////////
int nRowsToCreate(50000);
cout << endl << "Transaction test, creating " << nRowsToCreate;
cout << " rows please wait..." << endl;
tmStart = time(0);
db.execDML("begin transaction;");
for (i = 0; i < nRowsToCreate; i++)
{
char buf[128];
sprintf(buf, "insert into emp values (%d, 'Empname%06d');", i, i);
db.execDML(buf);
}
db.execDML("commit transaction;");
tmEnd = time(0);
////////////////////////////////////////////////////////////////
// Demonstrate CppSQLite3DB::execScalar()
////////////////////////////////////////////////////////////////
cout << db.execScalar("select count(*) from emp;")
<< " rows in emp table in ";
cout << tmEnd-tmStart << " seconds (that was fast!)" << endl;
////////////////////////////////////////////////////////////////
// Re-create emp table with auto-increment field
////////////////////////////////////////////////////////////////
cout << endl << "Auto increment test" << endl;
db.execDML("drop table emp;");
db.execDML(
"create table emp(empno integer primary key, empname char(20));");
cout << nRows << " rows deleted" << endl;
for (i = 0; i < 5; i++)
{
char buf[128];
sprintf(buf,
"insert into emp (empname) values ('Empname%06d');", i+1);
db.execDML(buf);
cout << " primary key: " << db.lastRowId() << endl;
}
///////////////////////////////////////////////////////////////////
// Query data and also show results of inserts into auto-increment field
//////////////////////////////////////////////////////////////////
cout << endl << "Select statement test" << endl;
CppSQLite3Query q = db.execQuery("select * from emp order by 1;");
for (fld = 0; fld < q.numFields(); fld++)
{
//cout << q.fieldName(fld) << "(" << q.fieldType(ld) << ")|";
cout << q.fieldName(fld) << "(" << q.fieldDataType(fld) << ")|";
}
cout << endl;
while (!q.eof())
{
cout << q.fieldValue(0) << "|";
cout << q.fieldValue(1) << "|" << endl;
q.nextRow();
}
///////////////////////////////////////////////////////////////
// SQLite's printf() functionality. Handles embedded quotes and NULLs
////////////////////////////////////////////////////////////////
cout << endl << "SQLite sprintf test" << endl;
CppSQLite3Buffer bufSQL;
bufSQL.format("insert into emp (empname) values (%Q);", "He's bad");
//.........这里部分代码省略.........