internal ComBuffer(Connection.CLICommand cmd, int id) { int size = 12; buf = new byte[size]; pos = 0; putInt(size); putInt((int)cmd); putInt(id); }
internal object getObject(Connection.CLICommand cmd, int n) { if (stmt == null) { throw new CliError("ObjectSet was aleady closed"); } if (stmt.con == null) { throw new CliError("Statement was closed"); } ComBuffer buf = new ComBuffer(cmd, stmt.stmtId); if (cmd == Connection.CLICommand.cli_cmd_skip) { buf.putInt(n); } stmt.con.send(buf); buf.reset(4); stmt.con.receive(buf, 4); int len = buf.getInt(); if (len == (int)Connection.CLIStatus.cli_not_found) { return null; } else if (len <= 0) { throw new CliError("Failed to get object"); } buf.reset(len-4); stmt.con.receive(buf, len-4); currOid = buf.getInt(); if (currOid == 0) { return null; } updated = false; return currObj = stmt.tableDesc.readObject(buf); }
internal Statement(Connection con, string sql, int stmtId) { this.stmtId = stmtId; int src = 0, dst = 0, len = sql.Length; int p = sql.IndexOf("from"); if (p < 0 && (p = sql.IndexOf("FROM")) < 0) { throw new CliError("Bad statment: SELECT FROM expected"); } p += 5; while (p < len && sql[p] == ' ') { p += 1; } int q = p; while (++q < len && sql[q] != ' '); if (p+1 == q) { throw new CliError("Bad statment: table name expected after FROM"); } string tableName = sql.Substring(p, q-p); lock (Connection.tableHash) { tableDesc = (TableDescriptor)Connection.tableHash[tableName]; if (tableDesc == null) { Type tableClass = Type.GetType(tableName); if (tableClass == null) { if (con.pkgs != null) { foreach (string pkg in con.pkgs) { tableClass = Type.GetType(pkg + '.' + tableName); if (tableClass != null) { break; } } } if (tableClass == null) { foreach (Assembly ass in AppDomain.CurrentDomain.GetAssemblies()) { foreach (Module mod in ass.GetModules()) { foreach (Type t in mod.FindTypes(new TypeFilter(FindTypeByName), tableName)) { if (tableClass != null) { throw new CliError("Class " + tableName + " exists in more than one scope"); } tableClass = t; } } } } if (tableClass == null) { throw new CliError("Class " + tableName + " not found"); } } tableDesc = new TableDescriptor(tableClass); Connection.tableHash[tableName] = tableDesc; } } byte[] buf = new byte[len]; while (src < len) { char ch = sql[src]; if (ch == '\'') { do { do { buf[dst++] = (byte)sql[src++]; if (src == len) { throw new CliError("Unterminated string constant in query"); } } while (sql[src] != '\''); buf[dst++] = (byte)'\''; } while (++src < len && sql[src] == '\''); } else if (ch == '%') { int begin = src; do { if (++src == len) { break; } ch = sql[src]; } while ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') || ch == '_'); if (ch == '%') { throw new CliError("Invalid parameter name"); } Parameter param = new Parameter(sql.Substring(begin, src-begin)); if (lastParam == null) { parameters = param; } else { lastParam.next = param; } lastParam = param; nParams += 1; buf[dst++] = (byte)'\0'; } else { buf[dst++]= (byte)sql[src++]; } } stmt = buf; stmtLen = dst; this.con = con; }
/// <summary> /// Close the statement. This method release all resource assoiated with statement /// at client and server. f close method will not be called, cleanup still /// will be performed later when garbage collector call finilize method of this /// object /// </summary> /// public void close() { if (con == null) { throw new CliError("Statement already closed"); } ComBuffer buf = new ComBuffer(Connection.CLICommand.cli_cmd_free_statement, stmtId); con.send(buf); con = null; }
internal ComBuffer(Connection.CLICommand cmd) : this(cmd, 0) { }