本文整理汇总了C#中QueryBuilder.addField方法的典型用法代码示例。如果您正苦于以下问题:C# QueryBuilder.addField方法的具体用法?C# QueryBuilder.addField怎么用?C# QueryBuilder.addField使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryBuilder
的用法示例。
在下文中一共展示了QueryBuilder.addField方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: updateQueryHandler
static void updateQueryHandler(ref QueryBuilder newQuery, string sqlStr)
{
string[] tokenList = new string[] { "update", "set", "where", "nullterminator" };
string tmp = "";
System.Collections.ArrayList tokenised = new System.Collections.ArrayList();
System.Collections.Hashtable tokenized = new System.Collections.Hashtable();
newQuery.setType(ABSTRACTQUERYTYPES.UpdateQuery);
for (int i = 0; i < tokenList.Length; i++)
{
if (sqlStr.IndexOf(tokenList[i]) >= 0)
{
if (sqlStr.IndexOf(tokenList[i + 1]) >= 0)
tmp = sqlStr.Substring(sqlStr.IndexOf(tokenList[i]), (sqlStr.IndexOf(tokenList[i + 1]) - sqlStr.IndexOf(tokenList[i])));
else
tmp = sqlStr.Substring(sqlStr.IndexOf(tokenList[i]));
tokenized.Add(tokenList[i], tmp);
}
}
foreach (string tokenkey in tokenized.Keys)
{
string tokenString = (string)tokenized[tokenkey];
string comString = tokenkey;
string paramString = tokenString.Substring(tokenString.IndexOf(tokenkey) + tokenkey.Length + 1).Trim();
//string comString = tokenString.Substring(0, tokenString.IndexOf(" ")).Trim();
//string paramString = tokenString.Substring(tokenString.IndexOf(" ") + 1).Trim();
string tablename = "";
switch (comString)
{
case "update":
tablename = paramString;
newQuery.addSource(tablename);
break;
case "set":
// set something=something, ilsjeiljg='sejil=gji\'seg', sjegiiljseg=slegijl
string curKey = ""; string curVal = "";
bool strQuoting = false;
bool doKey = false;
bool doAdd = false;
for (int i = 0; i < paramString.Length+1; i++)
{
if (!doKey)
{
if (paramString[i].Equals('='))
doKey = true;
else if (!paramString[i].Equals(',') && !paramString[i].Equals(' '))
curKey += paramString[i];
}
else
{
if (i < paramString.Length)
{
if ((paramString[i].Equals('\'')) && (!paramString[i - 1].Equals('\\')))
{
if (strQuoting)
{
strQuoting = false;
doAdd = true;
}
else
{
strQuoting = true; i++;
}
}
else if ((paramString[i].Equals(',')) && (strQuoting == false))
{
doAdd = true;
i++;
}
}
else doAdd = true;
if (doAdd)
{
string fieldname = curKey;
string fieldValue = curVal;
strQuoting = false;
doAdd = false;
doKey = false;
newQuery.addField(new AField(fieldname.Trim(), fieldValue.Trim()));
curKey = "";
curVal = "";
}
else
{
curVal += paramString[i];
}
}
}
break;
case "where":
//.........这里部分代码省略.........
示例2: insertQueryHandler
static void insertQueryHandler(ref QueryBuilder newQuery, string sqlStr)
{
try
{
newQuery.setType(ABSTRACTQUERYTYPES.InsertQuery);
string[] tokens = sqlStr.Split(' ');
System.Collections.Queue fieldQueue = new System.Collections.Queue(15);
for (int i = 0; i < tokens.Length; i++)
{
string tokenPeek = tokens[i];
if (tokens[i].Equals("into")) //Next token will be the tablename
newQuery.addSource(tokens[++i]);
if ((tokens[i].Equals("(")) && (!tokens[i - 2].Equals("values")))
{ //fieldlist
// process fieldlist
string fieldname;
i++; //just move forward to the tagset.
while (!tokens[i].Equals(")"))
{
fieldname = tokens[i++];
if (fieldname.Trim().Substring(fieldname.Length - 1).Equals(","))
fieldname = fieldname.Trim().Substring(0, fieldname.Trim().Length - 1);
foreach(string field in fieldname.Split(','))
fieldQueue.Enqueue(field);
}
string test = tokens[i + 1];
}
else if ((tokens[i + 1].Equals("(")) && (tokens[i].ToLower().Equals("values")))
{ //valuelist
// process valuelist
i++; i++;
string restOfString = "";
while (i < tokens.Length)
restOfString += tokens[i++] + " ";
int strquoteon = 0;
string fieldVal = "";
bool quotedType = false;
for (int x = 0; x < restOfString.Length; x++)
{
if ((restOfString[x].Equals('\'')) & (strquoteon == 0))
{
strquoteon = 1;
quotedType = true;
//x++; //skip the quote
fieldVal = "";
//fieldVal += restOfString[x];
}
else if ((strquoteon == 0) & ((restOfString[x].Equals(',')) | (restOfString[x].Equals(')'))))
{
string fieldname = (string)fieldQueue.Dequeue();
// Make sure we're not quoting.
newQuery.addField(new AField(fieldname, fieldVal.Trim()));
fieldVal = "";
quotedType = false;
}
else if (x > 0)
{
if ((restOfString[x].Equals('\'')) & !((restOfString[x - 1].Equals('\\'))))
{
strquoteon = 0;
//fieldVal += restOfString[x];
}
else
{
if (!((strquoteon == 0) && (quotedType == true)))
fieldVal += restOfString[x];
}
}
else
{
fieldVal += restOfString[x];
}
}
break;
}
}
}
catch (Exception e)
{
newQuery = null;
}
}
示例3: selectQueryHandler
//.........这里部分代码省略.........
//string comString = tokenString.Substring(0, tokenString.IndexOf(" ")).Trim();
//string paramString = tokenString.Substring(tokenString.IndexOf(" ") + 1).Trim();
string tableAlias = ""; string tablename = "";
string[] fieldList;
switch (comString)
{
case "select":
string[] fieldnames = paramString.Split(',');
string realname = "";
string agg;
ABSTRACTAGGREGATE aggMode = ABSTRACTAGGREGATE.None;
foreach (string field in fieldnames)
{
realname = field;
if (field.IndexOf(")") > 0)
{
realname = field.Substring(field.IndexOf("(") + 1, field.IndexOf(")") - field.IndexOf("(") - 1);
realname = realname.Trim();
agg = field.Substring(0, field.IndexOf("(") - 1);
switch (agg)
{
case "count":
aggMode = ABSTRACTAGGREGATE.Count;
break;
case "max":
aggMode = ABSTRACTAGGREGATE.Max;
break;
case "min":
aggMode = ABSTRACTAGGREGATE.Min;
break;
}
}
if (realname.IndexOf(".") > 0)
newQuery.addField(new AField(realname.Substring(realname.IndexOf(".") + 1), null, realname.Substring(0, realname.IndexOf("."))));
else
newQuery.addField(new AField(realname, null, (ATable)((QueryBuilder.SOURCEBINDING)newQuery.getSourceList()[0]).sourceObject));
if (realname.IndexOf(".") > 0)
newQuery.getField(realname.Substring(realname.IndexOf(".") + 1), realname.Substring(0, realname.IndexOf("."))).function = aggMode;
else
newQuery.getField(realname).function = aggMode;
}
break;
case "from":
if (paramString.IndexOf(' ') != -1) {
tableAlias = paramString.Substring(paramString.IndexOf(' ') + 1);
tablename = paramString.Substring(0, paramString.IndexOf(' '));
}
else
tablename = paramString.Trim();
newQuery.addSource(new ATable(tablename, tableAlias));
break;
case "inner join":
System.Collections.ArrayList joinList = new System.Collections.ArrayList();
paramString = "inner join " + paramString;
if (paramString.ToLower().IndexOf("inner join", "inner join".Length + 1) >= 2)
{
while (paramString.Length >= 0)
{
string tmp2 = paramString;
if (paramString.ToLower().IndexOf("inner join", "inner join".Length + 1) >= 2)
tmp2 = paramString.ToLower().Substring(0, paramString.ToLower().IndexOf("inner join", "inner join".Length + 2)).Trim();
else
{
示例4: CreateQueryBuilder
public static QueryBuilder CreateQueryBuilder(string csql, Database dbObj)
{
// This function will create a querybuilder object from commonsql
QueryBuilder newQuery = new QueryBuilder(dbObj);
// normalize commonsql:
int offset = 0;
if (csql.IndexOf(";") <= 0) csql += ";";
for (int i = 0; i < (csql.Length-offset); i++)
{
if ((csql[i + offset].Equals('(') || csql[i + offset].Equals(')')) && (!csql[(i + offset) - 1].Equals(' ')))
{ // space to the left
csql = csql.Insert((i+(offset++)), " ");
}
if ((csql[i + offset].Equals('(') || csql[i + offset].Equals(')')) && (!csql[(i + offset) + 1].Equals(' ')))
{ // space to the left
csql = csql.Insert((i + (offset++)) + 1, " ");
}
}
// endnormalize
string[] sqlStatements = csql.Split(';');
foreach (string sqlStr in sqlStatements)
{
if (!sqlStr.Trim().Equals(""))
{
//if (sqlStr.Substring(sqlStr.Length - 1).Equals(";"))
// sqlStr = sqlStr.Substring(0, sqlStr.Length - 1);
string[] tokens = sqlStr.Split(' ');
switch (tokens[0].ToLower())
{
case "drop":
if (tokens[1].ToLower().Equals("table"))
newQuery.setType(ABSTRACTQUERYTYPES.DropQuery);
if (tokens[1].ToLower().Equals("database"))
newQuery.setType(ABSTRACTQUERYTYPES.DropQuery);
newQuery.addSource(tokens[2].ToLower());
newQuery.addField(new AField("droptype", tokens[1].ToLower()));
break;
case "insert":
insertQueryHandler(ref newQuery, sqlStr);
break;
case "delete":
deleteQueryHandler(ref newQuery, sqlStr);
break;
case "show":
break;
case "select":
selectQueryHandler(ref newQuery, sqlStr);
break;
case "update":
updateQueryHandler(ref newQuery, sqlStr);
break;
case "alter":
alterQueryHandler(ref newQuery, sqlStr);
break;
}
}
}
return newQuery;
}