CallInfo _GetSelectPartCalls(ref string calls) { CallInfo ci = new CallInfo(); { string colpart = Qa.NextPart(ref calls); if (0 == colpart.Length) { throw new Exception("Expected value"); } if ("-" == colpart || "+" == colpart) { colpart += Qa.NextPart(ref calls); } string s; s = Qa.NextPart(ref calls); if ("(" == s) { List <CallInfoArg> args = new List <CallInfoArg>(4); { string xcalls = calls; if (")" == Qa.NextPart(ref xcalls)) { calls = xcalls; ci.func = colpart; ci.args = args; return(ci); } } for (; ;) { CallInfo nestci = _GetSelectPartCalls(ref calls); CallInfoArg arg = new CallInfoArg(); if (nestci.func == null) { #if DEBUG if (1 != nestci.args.Count) { throw new Exception("DEBUG: (1 != nestci.args.Count)"); } #endif arg = nestci.args[0]; } else { arg.nest = nestci; } args.Add(arg); s = Qa.NextPart(ref calls); if (0 == string.Compare("AS", s, true)) { arg = new CallInfoArg(); { StringBuilder sbas = new StringBuilder(); int asparens = 0; for (; ;) { s = Qa.NextPart(ref calls); if (0 == s.Length || "," == s) { //calls += s; break; } else if ("(" == s) { asparens++; sbas.Append(s); } else if (")" == s) { if (0 == asparens) { //calls += s; break; } asparens--; sbas.Append(s); } else { sbas.Append(s); } } if (0 == sbas.Length) { throw new Exception("Expected type after AS"); } { DbValue iterval = functools.AllocValue(mstring.Prepare("AS " + sbas.ToString())); // Need to copy the value out of the functools memory // so that it survives this map/reduce iteration... DbType xtype; ByteSlice iterbs = iterval.Eval(out xtype); List <byte> newbuf = new List <byte>(iterbs.Length); iterbs.AppendTo(newbuf); arg.value = new ImmediateValue(null, ByteSlice.Prepare(newbuf), xtype); } args.Add(arg); } //s = Qa.NextPart(ref calls); } if (s == ",") { continue; } if (s == ")") { string xnc = calls; s = Qa.NextPart(ref xnc); if (0 == s.Length || "," == s || ")" == s || 0 == string.Compare(s, "AS", true)) { ci.func = colpart; ci.args = args; return(ci); } else { throw new Exception("Unexpected: " + s); } break; } else { if (s.Length != 0) { throw new Exception("Unexpected: " + s); } throw new Exception("Unexpected end of select clause"); } } // Doesn't reach here. } else { //if (0 == s.Length || "," == s || ")" == s) { calls = s + " " + calls; // Undo. //ci.func = null; CallInfoArg arg; arg = new CallInfoArg(); //arg.s = colpart; if (colpart.Length > 0 && (char.IsLetter(colpart[0]) || '_' == colpart[0])) { int icol = DbColumn.IndexOf(cols, colpart); if (-1 == icol) { throw new Exception("No such column named " + colpart); } arg.value = new ColValue(this, cols[icol]); } else { DbTypeID typeid; ByteSlice bs = Types.LiteralToValue(colpart, out typeid); arg.value = new ImmediateValue(null, bs, DbType.Prepare(bs.Length, typeid)); } ci.args = new CallInfoArg[1]; ci.args[0] = arg; return(ci); } /*else * { * throw new Exception("Unexpected: " + s); * }*/ } } }
CallInfo _GetSelectPartCalls(ref string calls) { CallInfo ci = new CallInfo(); { string colpart = Qa.NextPart(ref calls); if (0 == colpart.Length) { throw new Exception("Expected value"); } if ("-" == colpart || "+" == colpart) { colpart += Qa.NextPart(ref calls); } string s; s = Qa.NextPart(ref calls); if ("(" == s) { List<CallInfoArg> args = new List<CallInfoArg>(4); { string xcalls = calls; if (")" == Qa.NextPart(ref xcalls)) { calls = xcalls; ci.func = colpart; ci.args = args; return ci; } } for (; ; ) { CallInfo nestci = _GetSelectPartCalls(ref calls); CallInfoArg arg = new CallInfoArg(); if (nestci.func == null) { #if DEBUG if (1 != nestci.args.Count) { throw new Exception("DEBUG: (1 != nestci.args.Count)"); } #endif arg = nestci.args[0]; } else { arg.nest = nestci; } args.Add(arg); s = Qa.NextPart(ref calls); if (0 == string.Compare("AS", s, true)) { arg = new CallInfoArg(); { StringBuilder sbas = new StringBuilder(); int asparens = 0; for (; ; ) { s = Qa.NextPart(ref calls); if (0 == s.Length || "," == s) { //calls += s; break; } else if ("(" == s) { asparens++; sbas.Append(s); } else if (")" == s) { if (0 == asparens) { //calls += s; break; } asparens--; sbas.Append(s); } else { sbas.Append(s); } } if (0 == sbas.Length) { throw new Exception("Expected type after AS"); } { DbValue iterval = functools.AllocValue(mstring.Prepare("AS " + sbas.ToString())); // Need to copy the value out of the functools memory // so that it survives this map/reduce iteration... DbType xtype; ByteSlice iterbs = iterval.Eval(out xtype); List<byte> newbuf = new List<byte>(iterbs.Length); iterbs.AppendTo(newbuf); arg.value = new ImmediateValue(null, ByteSlice.Prepare(newbuf), xtype); } args.Add(arg); } //s = Qa.NextPart(ref calls); } if (s == ",") { continue; } if (s == ")") { string xnc = calls; s = Qa.NextPart(ref xnc); if (0 == s.Length || "," == s || ")" == s || 0 == string.Compare(s, "AS", true)) { ci.func = colpart; ci.args = args; return ci; } else { throw new Exception("Unexpected: " + s); } break; } else { if (s.Length != 0) { throw new Exception("Unexpected: " + s); } throw new Exception("Unexpected end of select clause"); } } // Doesn't reach here. } else { //if (0 == s.Length || "," == s || ")" == s) { calls = s + " " + calls; // Undo. //ci.func = null; CallInfoArg arg; arg = new CallInfoArg(); //arg.s = colpart; if (colpart.Length > 0 && (char.IsLetter(colpart[0]) || '_' == colpart[0])) { int icol = DbColumn.IndexOf(cols, colpart); if (-1 == icol) { throw new Exception("No such column named " + colpart); } arg.value = new ColValue(this, cols[icol]); } else { DbTypeID typeid; ByteSlice bs = Types.LiteralToValue(colpart, out typeid); arg.value = new ImmediateValue(null, bs, DbType.Prepare(bs.Length, typeid)); } ci.args = new CallInfoArg[1]; ci.args[0] = arg; return ci; } /*else { throw new Exception("Unexpected: " + s); }*/ } } }