本文整理汇总了C++中Lex::get_type方法的典型用法代码示例。如果您正苦于以下问题:C++ Lex::get_type方法的具体用法?C++ Lex::get_type怎么用?C++ Lex::get_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lex
的用法示例。
在下文中一共展示了Lex::get_type方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Delete
const string DBMS::Delete (const string& tbname, Poliz& whereCl)
{
int affR = 0;
if (getTableStruct(tbname).numRecords == 0)
return "OK. \n0 affected rows.\n\n";
lockTable(tbname);
moveToStart(tbname);
Lex res;
IntWrap ind = nameMap[tbname];
if (!ind || deleted[ind])
throw TableNotFound();
while (!afterTableEnd(tbname))
{
evaluateExpr(tbname, whereCl);
res = pst[0];
if (res.get_type() != Lex_Bool)
{
throw TypeMismatch("WHERE-clause expected a boolean expression as it's argument.");
}
if (res.get_value()) // подходит под where-клаузу
{
tables[ind]->removeCurrentRecord();
++affR;
}
else
moveNext(tbname);
}
moveToStart(tbname);
unlockTable(tbname);
stringstream s;
s << "OK.\n" << affR << " affected rows.\n\n";
return s.str();
}
示例2: Update
const string DBMS::Update(const string& tbname, const string& fdname, Poliz& expr, Poliz& whereCl)
{
int affR = 0;
lockTable(tbname);
if (getTableStruct(tbname).numRecords == 0)
return "OK.\n0 affected rows.\n\n";
moveToStart(tbname);
Lex res;
stringstream buf;
ITBField* fdp;
IntWrap ind = nameMap[tbname];
if (!ind || deleted[ind])
throw TableNotFound();
while (!afterTableEnd(tbname))
{
evaluateExpr(tbname, whereCl);
res = pst[0];
if (res.get_type() != Lex_Bool)
{
throw TypeMismatch("WHERE-clause expected a boolean expression as it's argument.");
}
if (res.get_value()) // подходит под where-клаузу
{
++affR;
pst.clear();
evaluateExpr(tbname, expr);
res = pst[0];
fdp = getField(tbname, fdname);
if (getFieldType(tbname, fdname) == Long)
{
if (res.get_type() != Lex_Num)
{
throw TypeMismatch("Type mismatch in UPDATE: LONG expression expected.");
}
buf << res.get_value() << endl;
fdp->read(buf);
}
else
{
if (res.get_type() != Lex_Str)
{
throw TypeMismatch("Type mismatch in UPDATE: LONG expression expected.");
}
buf << res.get_str_value() << endl;
fdp->read(buf);
}
}
moveNext(tbname);
}
moveToStart(tbname);
unlockTable(tbname);
stringstream s;
s << "OK.\n" << affR << " affected rows.\n\n";
return s.str();
}
示例3: Select
const string DBMS::Select(const string& tbname, vector<string>& fdList, Poliz& whereCl)
{
stringstream result;
if (fdList.size() == 1 && fdList[0] == "*")
{
fdList = getTableStruct(tbname).names;
}
Table* tab = new Table("from "+tbname);
tab->tbstr.names = fdList;
tab->tbstr.numFields = fdList.size();
tab->tbstr.numRecords = 0;
if (getTableStruct(tbname).numRecords == 0)
{
result << *tab << endl << "OK." << endl;
return result.str();
}
moveToStart(tbname);
IntWrap ind;
for (int i = 0; i < tab->tbstr.numFields; ++i)
{
tab->tbstr.types.push_back( getFieldType(tbname, fdList[i]) );
tab->tbstr.nameMap[fdList[i]] = i;
}
Lex res;
stringstream buf;
ITBField* buf_fd;
while (!afterTableEnd(tbname))
{
evaluateExpr(tbname, whereCl);
res = pst[0];
if (res.get_type() != Lex_Bool)
{
throw TypeMismatch("WHERE-clause expected a boolean expression as it's argument.");
}
if (res.get_value()) // подходит под where-клаузу
{
tab->records.push_back( new ITBField* [tab->tbstr.numFields] );
for (int k = 0; k < tab->tbstr.numFields; ++k)
{
if (tab->tbstr.types[k] == Long)
{
(*(tab->records.rbegin()))[k] = new TBFieldLong();
}
else
{
(*(tab->records.rbegin()))[k] = new TBFieldText();
}
IntWrap ii = tab->tbstr.nameMap[fdList[k]];
if (!ii)
{
throw FieldNotFound();
}
buf_fd = getField(tbname, tab->tbstr.names[ii]);
buf_fd->write(buf, false);
buf << endl;
(*(tab->records.rbegin()))[k]->read(buf);
}
++(tab->tbstr.numRecords);
if (tab->currentId == -1)
{
tab->currentId = 0;
tab->currentRecord = tab->records.begin();
}
}
moveNext(tbname);
}
result << *tab << endl << "OK.\n\n" << endl;
moveToStart(tbname);
return result.str();
}