Exemplo n.º 1
0
        /// <summary>
        /// Drop specified table
        /// </summary>
        /// <param name="tableName">name of the table</param>
        ///
        public void dropTable(String tableName)
        {
            ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_drop_table);

            buf.putAsciiz(tableName);
            sendReceive(buf);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Update the current object in the set. Changes made in the current object
        /// are saved in the database
        /// </summary>
        ///
        public void update()
        {
            if (stmt == null)
            {
                throw new CliError("ObjectSet was aleady closed");
            }
            if (stmt.con == null)
            {
                throw new CliError("Statement was closed");
            }
            if (currOid == 0)
            {
                throw new CliError("No object was selected");
            }
            if (!stmt.forUpdate)
            {
                throw new CliError("Updates not allowed");
            }
            if (updated)
            {
                throw new CliError("Record was already updated");
            }
            ComBuffer buf = new ComBuffer(Connection.CLICommand.cli_cmd_update, stmt.stmtId);

            stmt.tableDesc.writeColumnValues(buf, currObj);
            stmt.con.sendReceive(buf);
        }
Exemplo n.º 3
0
 internal void writeColumnDefs(ComBuffer buf)
 {
     for (int i = 0, n = nColumns; i < n; i++)
     {
         buf.putByte((int)types[i]);
         buf.putAsciiz(columns[i].Name);
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Drop index
        /// </summary>
        /// <param name="tableName">name of the table</param>
        /// <param name="fieldName">name of the field</param>
        ///
        public void dropIndex(String tableName, String fieldName)
        {
            ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_alter_index);

            buf.putAsciiz(tableName);
            buf.putAsciiz(fieldName);
            buf.putByte(0);
            sendReceive(buf);
        }
Exemplo n.º 5
0
        /// <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;
        }
Exemplo n.º 6
0
        /// <summary>
        /// Add case sensitive index
        /// </summary>
        /// <param name="tableName">name of the table</param>
        /// <param name="fieldName">name of the field</param>
        /// <param name="caseInsensitive">attribute specifying whether index is case insensitive or not</param>
        ///
        public void addIndex(String tableName, String fieldName, bool caseInsensitive)
        {
            ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_alter_index);

            buf.putAsciiz(tableName);
            buf.putAsciiz(fieldName);
            buf.putByte(caseInsensitive
                    ? (int)(CLIFieldQualifier.cli_indexed | CLIFieldQualifier.cli_case_insensitive)
                    : (int)CLIFieldQualifier.cli_indexed);
            sendReceive(buf);
        }
Exemplo n.º 7
0
        internal int sendReceive(ComBuffer buf)
        {
            send(buf);
            receive(buf, 4);
            int rc = buf.getInt();

            if (rc < 0)
            {
                throw new CliError("Request failed with status " + rc);
            }
            return(rc);
        }
Exemplo n.º 8
0
        /// <summary>
        /// Insert object in the database. There is should be table in the database with
        /// name equal to the full class name of the inserted object (comparison is
        /// case sensitive). GigaBASE will store to the database all non-static and
        /// non-transient fields from the class. All Java primitive types,
        /// <code>java.lang.string</code>, arrays of primitive types or strings, <code>java.util.Date</code>
        /// are supported by GigaBASE. If <code>int</code> field is marked as <code>volatile</code>, it
        /// is assumed to be autoincremented field - unique value to this field is assigned automatically
        /// by GigaBASE.
        /// </summary>
        /// <param name="obj">object to be inserted inthe database</param>
        /// <returns>reference to the inserted object</returns>
        ///
        public Reference insert(object obj)
        {
            if (socket == null)
            {
                throw new CliError("Session is not opened");
            }
            Type            clazz     = obj.GetType();
            string          className = clazz.Name;
            TableDescriptor tableDesc;

            lock (tableHash) {
                tableDesc = (TableDescriptor)tableHash[className];
                if (tableDesc == null)
                {
                    tableDesc            = new TableDescriptor(clazz);
                    tableHash[className] = tableDesc;
                }
            }
            ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_prepare_and_insert);

            buf.putAsciiz("insert into " + className);
            buf.putByte(tableDesc.nColumns);
            tableDesc.writeColumnDefs(buf);
            tableDesc.writeColumnValues(buf, obj);
            send(buf);
            receive(buf, 12);
            CLIStatus rc = (CLIStatus)buf.getInt();

            if (rc == CLIStatus.cli_ok)
            {
                int rowid = buf.getInt();
                int oid   = buf.getInt();
                if (tableDesc.autoincrement)
                {
                    for (int i = tableDesc.nColumns; --i >= 0;)
                    {
                        if (tableDesc.types[i] == CLIType.cli_autoincrement)
                        {
                            tableDesc.columns[i].SetValue(obj, rowid);
                        }
                    }
                }
                return((oid != 0) ? new Reference(oid) : null);
            }
            else
            {
                throw new CliError("Insert object operation failed with status " + rc);
            }
        }
Exemplo n.º 9
0
        internal void send(ComBuffer com)
        {
            int rc;

            com.end();
            for (int size = com.pos, offs = 0; size != 0; size -= rc, offs += rc)
            {
                int chunk = size > MaxSendParcelSize ? MaxSendParcelSize : size;
                rc = socket.Send(com.buf, offs, chunk, SocketFlags.None);
                if (rc <= 0)
                {
                    throw new CliError("Socket write failed");
                }
            }
        }
Exemplo n.º 10
0
        internal void receive(ComBuffer com, int len)
        {
            com.reset(len);
            int offs = 0;

            while (len > 0)
            {
                int rc = socket.Receive(com.buf, offs, len, SocketFlags.None);
                if (rc < 0)
                {
                    throw new CliError("Failed to read response");
                }
                len  -= rc;
                offs += rc;
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Close connection with server
        /// </summary>
        ///
        public void close()
        {
            if (socket == null)
            {
                throw new CliError("Session is not opened");
            }
            if (pool != null)
            {
                pool.releaseConnection(this);
                return;
            }
            ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_close_session);

            send(buf);
            socket.Close();
            socket = null;
        }
Exemplo n.º 12
0
        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));
        }
Exemplo n.º 13
0
 internal void writeColumnDefs(ComBuffer buf)
 {
     for (int i = 0, n = nColumns; i < n; i++) {
     buf.putByte((int)types[i]);
     buf.putAsciiz(columns[i].Name);
     }
 }
Exemplo n.º 14
0
        /// <summary>
        /// Create table matching specified class.  Name of the table is equal
        /// to class name without any package prefixes. This table will include columns
        /// corresponsinf to all non-static and non-transient fields of specified class and base classes
        /// of this class.
        /// </summary>
        /// <param name="cls">Java class for which table should be created</param>
        /// <returns><code>true</code> if table sucessfully created, <code>false</code>
        /// if table already exists, throws <code>CliError</code> exception in case of all other errors</returns>
        ///
        public bool createTable(Type cls)
        {
            int i;

            if (socket == null)
            {
                throw new CliError("Session is not opened");
            }
            Type c;
            int  nColumns = 0;

            for (c = cls; c != null; c = c.BaseType)
            {
                FieldInfo[] classFields = c.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
                for (i = 0; i < classFields.Length; i++)
                {
                    if (!classFields[i].IsStatic && !classFields[i].IsNotSerialized)
                    {
                        nColumns += 1;
                    }
                }
            }
            ComBuffer buf       = new ComBuffer(CLICommand.cli_cmd_create_table);
            String    tableName = cls.Name;

            buf.putAsciiz(tableName);
            buf.putByte(nColumns);
            for (c = cls; c != null; c = c.BaseType)
            {
                FieldInfo[] classFields = c.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
                for (i = 0; i < classFields.Length; i++)
                {
                    FieldInfo f              = classFields[i];
                    String    refTableName   = "";
                    String    inverseRefName = "";
                    if (!f.IsStatic && !f.IsNotSerialized)
                    {
                        Type type = f.FieldType;
                        Connection.CLIType cliType;
                        if (type == typeof(byte))
                        {
                            cliType = Connection.CLIType.cli_int1;
                        }
                        else if (type == typeof(short))
                        {
                            cliType = Connection.CLIType.cli_int2;
                        }
                        else if (type == typeof(int))
                        {
                            if (f.GetCustomAttributes(typeof(AutoincrementAttribute), false).Length > 0)
                            {
                                cliType = Connection.CLIType.cli_autoincrement;
                            }
                            else
                            {
                                cliType = Connection.CLIType.cli_int4;
                            }
                        }
                        else if (type == typeof(bool))
                        {
                            cliType = Connection.CLIType.cli_bool;
                        }
                        else if (type == typeof(long))
                        {
                            cliType = Connection.CLIType.cli_int8;
                        }
                        else if (type == typeof(float))
                        {
                            cliType = Connection.CLIType.cli_real4;
                        }
                        else if (type == typeof(double))
                        {
                            cliType = Connection.CLIType.cli_real8;
                        }
                        else if (type == typeof(Reference))
                        {
                            cliType = Connection.CLIType.cli_oid;
                            object[] attribs = f.GetCustomAttributes(typeof(ReferencesAttribute), false);
                            if (attribs.Length == 0)
                            {
                                throw new CliError("Rererences attribute should be specified for rererence field");
                            }
                            ReferencesAttribute ra = (ReferencesAttribute)attribs[0];
                            if (ra.refTableName == null)
                            {
                                throw new CliError("Name of referenced table should be specified");
                            }
                            refTableName = ra.refTableName;
                            if (ra.inverseRefName != null)
                            {
                                inverseRefName = ra.inverseRefName;
                            }
                        }
                        else if (type == typeof(Rectangle))
                        {
                            cliType = Connection.CLIType.cli_rectangle;
                        }
                        else if (type == typeof(string))
                        {
                            cliType = Connection.CLIType.cli_asciiz;
                        }
                        else if (type == typeof(DateTime))
                        {
                            cliType = Connection.CLIType.cli_datetime;
                        }
                        else if (type.IsArray)
                        {
                            type = type.GetElementType();
                            if (type == typeof(byte))
                            {
                                cliType = Connection.CLIType.cli_array_of_int1;
                            }
                            else if (type == typeof(short))
                            {
                                cliType = Connection.CLIType.cli_array_of_int2;
                            }
                            else if (type == typeof(int))
                            {
                                cliType = Connection.CLIType.cli_array_of_int4;
                            }
                            else if (type == typeof(bool))
                            {
                                cliType = Connection.CLIType.cli_array_of_bool;
                            }
                            else if (type == typeof(long))
                            {
                                cliType = Connection.CLIType.cli_array_of_int8;
                            }
                            else if (type == typeof(float))
                            {
                                cliType = Connection.CLIType.cli_array_of_real4;
                            }
                            else if (type == typeof(double))
                            {
                                cliType = Connection.CLIType.cli_array_of_real8;
                            }
                            else if (type == typeof(Reference))
                            {
                                cliType = Connection.CLIType.cli_array_of_oid;
                                object[] attribs = f.GetCustomAttributes(typeof(ReferencesAttribute), false);
                                if (attribs.Length == 0)
                                {
                                    throw new CliError("Rererences attribute should be specified for rererence field");
                                }
                                ReferencesAttribute ra = (ReferencesAttribute)attribs[0];
                                if (ra.refTableName == null)
                                {
                                    throw new CliError("Name of referenced table should be specified");
                                }
                                refTableName = ra.refTableName;
                                if (ra.inverseRefName != null)
                                {
                                    inverseRefName = ra.inverseRefName;
                                }
                            }
                            else if (type == typeof(string))
                            {
                                cliType = Connection.CLIType.cli_array_of_string;
                            }
                            else
                            {
                                throw new CliError("Unsupported array type " + type.Name);
                            }
                        }
                        else
                        {
                            throw new CliError("Unsupported field type " + type.Name);
                        }
                        buf.putByte((int)cliType);
                        buf.putByte(0);
                        buf.putAsciiz(f.Name);
                        buf.putAsciiz(refTableName);
                        buf.putAsciiz(inverseRefName);
                    }
                }
            }
            send(buf);
            receive(buf, 4);
            int rc = buf.getInt();

            if (rc == (int)CLIStatus.cli_table_already_exists)
            {
                return(false);
            }
            else if (rc < 0)
            {
                throw new CliError("Create table failed with status: " + rc);
            }
            return(true);
        }
Exemplo n.º 15
0
 internal void writeColumnValues(ComBuffer buf, Object obj)
 {
     int i, j, n, len;
     for (i = 0, n = nColumns; i < n; i++)
     {
     switch (types[i])
     {
         case Connection.CLIType.cli_int1:
             buf.putByte((byte)columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_int2:
             buf.putShort((short)columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_int4:
             buf.putInt((int)columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_int8:
             buf.putLong((long)columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_real4:
             buf.putFloat((float)columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_real8:
             buf.putDouble((double)columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_bool:
             buf.putByte((bool)columns[i].GetValue(obj) ? 1 : 0);
             break;
         case Connection.CLIType.cli_oid:
             Reference r = (Reference)columns[i].GetValue(obj);
             buf.putInt(r != null ? r.oid : 0);
             break;
         case Connection.CLIType.cli_rectangle:
             Rectangle rect = (Rectangle)columns[i].GetValue(obj);
             if (rect == null)
             {
                 rect = new Rectangle();
             }
             buf.putRectangle(rect);
             break;
         case Connection.CLIType.cli_asciiz:
             buf.putString((string)columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_datetime:
             buf.putInt((int)(((DateTime)columns[i].GetValue(obj)).Ticks / 1000000));
             break;
         case Connection.CLIType.cli_array_of_int1:
             buf.putByteArray((byte[])columns[i].GetValue(obj));
             break;
         case Connection.CLIType.cli_array_of_int2:
         {
             short[] arr = (short[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putShort(arr[j]);
             }
             break;
         }
         case Connection.CLIType.cli_array_of_int4:
         {
             int[] arr = (int[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putInt(arr[j]);
             }
             break;
         }
         case Connection.CLIType.cli_array_of_int8:
         {
             long[] arr = (long[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putLong(arr[j]);
             }
             break;
         }
         case Connection.CLIType.cli_array_of_real4:
         {
             float[] arr = (float[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putFloat(arr[j]);
             }
             break;
         }
         case Connection.CLIType.cli_array_of_real8:
         {
             double[] arr = (double[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putDouble(arr[j]);
             }
             break;
         }
         case Connection.CLIType.cli_array_of_bool:
         {
             bool[] arr = (bool[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putByte(arr[j] ? 1 : 0);
             }
             break;
         }
         case Connection.CLIType.cli_array_of_oid:
         {
             Reference[] arr = (Reference[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putInt(arr[j] != null ? arr[j].oid : 0);
             }
             break;
         }
         case Connection.CLIType.cli_array_of_string:
         {
             string[] arr = (string[])columns[i].GetValue(obj);
             len = arr == null ? 0 : arr.Length;
             buf.putInt(len);
             for (j = 0; j < len; j++)
             {
                 buf.putAsciiz(arr[j]);
             }
             break;
         }
         case Connection.CLIType.cli_autoincrement:
             break;
         default:
             throw new CliError("Unsupported type " + types[i]);
     }
     }
 }
Exemplo n.º 16
0
 /// <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;
 }
Exemplo n.º 17
0
 /// <summary>
 /// Add case sensitive index
 /// </summary>
 /// <param name="tableName">name of the table</param>
 /// <param name="fieldName">name of the field</param>
 /// <param name="caseInsensitive">attribute specifying whether index is case insensitive or not</param>
 ///
 public void addIndex(String tableName, String fieldName, bool caseInsensitive)
 {
     ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_alter_index);
     buf.putAsciiz(tableName);
     buf.putAsciiz(fieldName);
     buf.putByte(caseInsensitive
             ? (int)(CLIFieldQualifier.cli_indexed|CLIFieldQualifier.cli_case_insensitive)
             : (int)CLIFieldQualifier.cli_indexed);
     sendReceive(buf);
 }
Exemplo n.º 18
0
 internal void receive(ComBuffer com, int len)
 {
     com.reset(len);
     int offs = 0;
     while (len > 0) {
     int rc = socket.Receive(com.buf, offs, len, SocketFlags.None);
     if (rc < 0) {
         throw new CliError("Failed to read response");
     }
     len -= rc;
     offs += rc;
     }
 }
Exemplo n.º 19
0
        internal void writeColumnValues(ComBuffer buf, Object obj)
        {
            int i, j, n, len;

            for (i = 0, n = nColumns; i < n; i++)
            {
                switch (types[i])
                {
                case Connection.CLIType.cli_int1:
                    buf.putByte((byte)columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_int2:
                    buf.putShort((short)columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_int4:
                    buf.putInt((int)columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_int8:
                    buf.putLong((long)columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_real4:
                    buf.putFloat((float)columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_real8:
                    buf.putDouble((double)columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_bool:
                    buf.putByte((bool)columns[i].GetValue(obj) ? 1 : 0);
                    break;

                case Connection.CLIType.cli_oid:
                    Reference r = (Reference)columns[i].GetValue(obj);
                    buf.putInt(r != null ? r.oid : 0);
                    break;

                case Connection.CLIType.cli_rectangle:
                    Rectangle rect = (Rectangle)columns[i].GetValue(obj);
                    if (rect == null)
                    {
                        rect = new Rectangle();
                    }
                    buf.putRectangle(rect);
                    break;

                case Connection.CLIType.cli_asciiz:
                    buf.putString((string)columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_datetime:
                    buf.putInt((int)(((DateTime)columns[i].GetValue(obj)).Ticks / 1000000));
                    break;

                case Connection.CLIType.cli_array_of_int1:
                    buf.putByteArray((byte[])columns[i].GetValue(obj));
                    break;

                case Connection.CLIType.cli_array_of_int2:
                {
                    short[] arr = (short[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putShort(arr[j]);
                    }
                    break;
                }

                case Connection.CLIType.cli_array_of_int4:
                {
                    int[] arr = (int[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putInt(arr[j]);
                    }
                    break;
                }

                case Connection.CLIType.cli_array_of_int8:
                {
                    long[] arr = (long[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putLong(arr[j]);
                    }
                    break;
                }

                case Connection.CLIType.cli_array_of_real4:
                {
                    float[] arr = (float[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putFloat(arr[j]);
                    }
                    break;
                }

                case Connection.CLIType.cli_array_of_real8:
                {
                    double[] arr = (double[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putDouble(arr[j]);
                    }
                    break;
                }

                case Connection.CLIType.cli_array_of_bool:
                {
                    bool[] arr = (bool[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putByte(arr[j] ? 1 : 0);
                    }
                    break;
                }

                case Connection.CLIType.cli_array_of_oid:
                {
                    Reference[] arr = (Reference[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putInt(arr[j] != null ? arr[j].oid : 0);
                    }
                    break;
                }

                case Connection.CLIType.cli_array_of_string:
                {
                    string[] arr = (string[])columns[i].GetValue(obj);
                    len = arr == null ? 0 : arr.Length;
                    buf.putInt(len);
                    for (j = 0; j < len; j++)
                    {
                        buf.putAsciiz(arr[j]);
                    }
                    break;
                }

                case Connection.CLIType.cli_autoincrement:
                    break;

                default:
                    throw new CliError("Unsupported type " + types[i]);
                }
            }
        }
Exemplo n.º 20
0
 /// <summary>
 /// Prepare (if needed) and execute select statement
 /// Only object set returned by the select for updated statement allows
 /// update and deletion of the objects.
 /// </summary>
 /// <param name="forUpdate">if cursor is opened in for update mode</param>
 /// <returns>object set with the selected objects</returns>
 ///
 public ObjectSet fetch(bool forUpdate)
 {
     int i, n;
     ComBuffer buf;
     if (!prepared) {
     buf = new ComBuffer(Connection.CLICommand.cli_cmd_prepare_and_execute, stmtId);
     n = tableDesc.nColumns;
     buf.putByte(nParams);
     buf.putByte(n);
     int len = stmtLen;
     bool addNull = false;
     if (len == 0 || stmt[len-1] != 0) {
         addNull = true;
         len += nParams;
         buf.putShort(len+1);
     } else {
         len += nParams;
         buf.putShort(len);
     }
     i = 0;
     Parameter p = parameters;
     do {
         byte ch = stmt[i++];
         buf.putByte(ch);
         len -= 1;
         if (ch == '\0') {
             if (len != 0) {
                 if (p.type == Connection.CLIType.cli_undefined) {
                     throw new CliError("Unbound parameter " + p.name);
                 }
                 buf.putByte((int)p.type);
                 p = p.next;
                 len -= 1;
             }
         }
     } while (len != 0);
     if (addNull) {
         buf.putByte('\0');
     }
     tableDesc.writeColumnDefs(buf);
     } else { // statement was already prepared
     buf = new ComBuffer(Connection.CLICommand.cli_cmd_execute, stmtId);
     }
     this.forUpdate = forUpdate;
     buf.putByte(forUpdate ? 1 : 0);
     for (Parameter p = parameters; p != null; p = p.next) {
     switch (p.type) {
       case Connection.CLIType.cli_oid:
       case Connection.CLIType.cli_int4:
         buf.putInt(p.ivalue);
         break;
       case Connection.CLIType.cli_int1:
       case Connection.CLIType.cli_bool:
         buf.putByte((byte)p.ivalue);
         break;
       case Connection.CLIType.cli_int2:
         buf.putShort((short)p.ivalue);
         break;
       case Connection.CLIType.cli_int8:
         buf.putLong(p.lvalue);
         break;
       case Connection.CLIType.cli_real4:
         buf.putFloat(p.fvalue);
         break;
       case Connection.CLIType.cli_real8:
         buf.putDouble(p.dvalue);
         break;
       case Connection.CLIType.cli_asciiz:
         buf.putAsciiz(p.svalue);
         break;
     }
     }
     prepared = true;
     return new ObjectSet(this, con.sendReceive(buf));
 }
Exemplo n.º 21
0
 /// <summary>
 /// Insert object in the database. There is should be table in the database with
 /// name equal to the full class name of the inserted object (comparison is 
 /// case sensitive). GigaBASE will store to the database all non-static and 
 /// non-transient fields from the class. All Java primitive types, 
 /// <code>java.lang.string</code>, arrays of primitive types or strings, <code>java.util.Date</code>
 /// are supported by GigaBASE. If <code>int</code> field is marked as <code>volatile</code>, it
 /// is assumed to be autoincremented field - unique value to this field is assigned automatically 
 /// by GigaBASE. 
 /// </summary>
 /// <param name="obj">object to be inserted inthe database</param>
 /// <returns>reference to the inserted object</returns>
 ///
 public Reference insert(object obj)
 {
     if (socket == null) {
     throw new CliError("Session is not opened");
     }
     Type clazz = obj.GetType();
     string className = clazz.Name;
     TableDescriptor tableDesc;
     lock (tableHash) {
     tableDesc = (TableDescriptor)tableHash[className];
     if (tableDesc == null) {
     tableDesc = new TableDescriptor(clazz);
     tableHash[className] = tableDesc;
     }
     }
     ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_prepare_and_insert);
     buf.putAsciiz("insert into " + className);
     buf.putByte(tableDesc.nColumns);
     tableDesc.writeColumnDefs(buf);
     tableDesc.writeColumnValues(buf, obj);
     send(buf);
     receive(buf, 12);
     CLIStatus rc = (CLIStatus)buf.getInt();
     if (rc == CLIStatus.cli_ok) {
     int rowid = buf.getInt();
     int oid = buf.getInt();
     if (tableDesc.autoincrement) {
     for (int i = tableDesc.nColumns; --i >= 0;) {
     if (tableDesc.types[i] == CLIType.cli_autoincrement) {
     tableDesc.columns[i].SetValue(obj, rowid);
     }
     }
     }
     return (oid != 0) ? new Reference(oid) : null;
     } else {
     throw new CliError("Insert object operation failed with status " + rc);
     }
 }
Exemplo n.º 22
0
 /// <summary>
 /// Update the current object in the set. Changes made in the current object 
 /// are saved in the database
 /// </summary>
 ///
 public void update()
 {
     if (stmt == null) {
     throw new CliError("ObjectSet was aleady closed");
     }
     if (stmt.con == null) {
     throw new CliError("Statement was closed");
     }
     if (currOid == 0) {
     throw new CliError("No object was selected");
     }
     if (!stmt.forUpdate) {
     throw new CliError("Updates not allowed");
     }
     if (updated) {
     throw new CliError("Record was already updated");
     }
     ComBuffer buf = new ComBuffer(Connection.CLICommand.cli_cmd_update, stmt.stmtId);
     stmt.tableDesc.writeColumnValues(buf, currObj);
     stmt.con.sendReceive(buf);
 }
Exemplo n.º 23
0
 /// <summary>
 /// Create table matching specified class.  Name of the table is equal
 /// to class name without any package prefixes. This table will include columns
 /// corresponsinf to all non-static and non-transient fields of specified class and base classes
 /// of this class. 
 /// </summary>
 /// <param name="cls">Java class for which table should be created</param>
 /// <returns><code>true</code> if table sucessfully created, <code>false</code> 
 /// if table already exists, throws <code>CliError</code> exception in case of all other errors</returns>
 ///
 public bool createTable(Type cls)
 {
     int i;
     if (socket == null) {
     throw new CliError("Session is not opened");
     }
     Type c;
     int nColumns = 0;
     for (c = cls; c != null; c = c.BaseType) {
     FieldInfo[] classFields = c.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
     for (i = 0; i < classFields.Length; i++) {
         if (!classFields[i].IsStatic && !classFields[i].IsNotSerialized) {
             nColumns += 1;
         }
     }
     }
     ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_create_table);
     String tableName = cls.Name;
     buf.putAsciiz(tableName);
     buf.putByte(nColumns);
     for (c = cls; c != null; c = c.BaseType) {
     FieldInfo[] classFields = c.GetFields(BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.DeclaredOnly);
     for (i = 0; i < classFields.Length; i++) {
     FieldInfo f = classFields[i];
         String refTableName = "";
         String inverseRefName = "";
         if (!f.IsStatic && !f.IsNotSerialized) {
             Type type = f.FieldType;
             Connection.CLIType cliType;
             if (type == typeof(byte)) {
                 cliType = Connection.CLIType.cli_int1;
             } else if (type == typeof(short)) {
                 cliType = Connection.CLIType.cli_int2;
             } else if (type == typeof(int)) {
                 if (f.GetCustomAttributes(typeof(AutoincrementAttribute), false).Length > 0) {
                     cliType = Connection.CLIType.cli_autoincrement;
                 }
                 else {
                     cliType = Connection.CLIType.cli_int4;
                 }
             } else if (type == typeof(bool)) {
                 cliType = Connection.CLIType.cli_bool;
             } else if (type == typeof(long)) {
                 cliType = Connection.CLIType.cli_int8;
             } else if (type == typeof(float)) {
                 cliType = Connection.CLIType.cli_real4;
             } else if (type == typeof(double)) {
                 cliType = Connection.CLIType.cli_real8;
             } else if (type == typeof(Reference)) {
                 cliType = Connection.CLIType.cli_oid;
                 object[] attribs = f.GetCustomAttributes(typeof(ReferencesAttribute), false);
                 if (attribs.Length == 0) {
                     throw new CliError("Rererences attribute should be specified for rererence field");
                 }
                 ReferencesAttribute ra = (ReferencesAttribute)attribs[0];
                 if (ra.refTableName == null) {
                     throw new CliError("Name of referenced table should be specified");
                 }
                 refTableName = ra.refTableName;
                 if (ra.inverseRefName != null) {
                     inverseRefName = ra.inverseRefName;
                 }
             } else if (type == typeof(Rectangle)) {
                 cliType = Connection.CLIType.cli_rectangle;
             } else if (type == typeof(string)) {
                 cliType = Connection.CLIType.cli_asciiz;
             } else if (type == typeof(DateTime)) {
                 cliType = Connection.CLIType.cli_datetime;
             } else if (type.IsArray) {
                 type = type.GetElementType();
                 if (type == typeof(byte)) {
                     cliType = Connection.CLIType.cli_array_of_int1;
                 } else if (type == typeof(short)) {
                     cliType = Connection.CLIType.cli_array_of_int2;
                 } else if (type == typeof(int)) {
                     cliType = Connection.CLIType.cli_array_of_int4;
                 } else if (type == typeof(bool)) {
                     cliType = Connection.CLIType.cli_array_of_bool;
                 } else if (type == typeof(long)) {
                     cliType = Connection.CLIType.cli_array_of_int8;
                 } else if (type == typeof(float)) {
                     cliType = Connection.CLIType.cli_array_of_real4;
                 } else if (type == typeof(double)) {
                     cliType = Connection.CLIType.cli_array_of_real8;
                 } else if (type == typeof(Reference)) {
                     cliType = Connection.CLIType.cli_array_of_oid;
                     object[] attribs = f.GetCustomAttributes(typeof(ReferencesAttribute), false);
                     if (attribs.Length == 0) {
                         throw new CliError("Rererences attribute should be specified for rererence field");
                     }
                     ReferencesAttribute ra = (ReferencesAttribute)attribs[0];
                     if (ra.refTableName == null) {
                         throw new CliError("Name of referenced table should be specified");
                     }
                     refTableName = ra.refTableName;
                     if (ra.inverseRefName != null) {
                         inverseRefName = ra.inverseRefName;
                     }
                 } else if (type == typeof(string)) {
                     cliType = Connection.CLIType.cli_array_of_string;
                 } else {
                     throw new CliError("Unsupported array type " + type.Name);
                 }
             } else {
                 throw new CliError("Unsupported field type " + type.Name);
             }
             buf.putByte((int)cliType);
             buf.putByte(0);
             buf.putAsciiz(f.Name);
             buf.putAsciiz(refTableName);
             buf.putAsciiz(inverseRefName);
         }
     }
     }
     send(buf);
     receive(buf, 4);
     int rc = buf.getInt();
     if (rc == (int)CLIStatus.cli_table_already_exists) {
     return false;
     } else if (rc < 0) {
     throw new CliError("Create table failed with status: " + rc);
     }
     return true;
 }
Exemplo n.º 24
0
 /// <summary>
 /// Close connection with server
 /// </summary>
 ///
 public void close()
 {
     if (socket == null) {
     throw new CliError("Session is not opened");
     }
     if (pool != null) {
     pool.releaseConnection(this);
     return;
     }
     ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_close_session);
     send(buf);
     socket.Close();
     socket = null;
 }
Exemplo n.º 25
0
 internal object readObject(ComBuffer buf)
 {
     Object obj = constructor.Invoke(constructorParameters);
     int i, j, n, len;
     for (i = 0, n = nColumns; i < n; i++)
     {
     Connection.CLIType type = (Connection.CLIType)buf.getByte();
     if (type != types[i])
     {
         throw new CliError("Unexpected type of column: " + type
             + " instead of " + types[i]);
     }
     switch (types[i])
     {
         case Connection.CLIType.cli_int1:
             columns[i].SetValue(obj, buf.getByte());
             break;
         case Connection.CLIType.cli_int2:
             columns[i].SetValue(obj, buf.getShort());
             break;
         case Connection.CLIType.cli_int4:
         case Connection.CLIType.cli_autoincrement:
             columns[i].SetValue(obj, buf.getInt());
             break;
         case Connection.CLIType.cli_int8:
             columns[i].SetValue(obj, buf.getLong());
             break;
         case Connection.CLIType.cli_real4:
             columns[i].SetValue(obj, buf.getFloat());
             break;
         case Connection.CLIType.cli_real8:
             columns[i].SetValue(obj, buf.getDouble());
             break;
         case Connection.CLIType.cli_bool:
             columns[i].SetValue(obj, buf.getByte() != 0);
             break;
         case Connection.CLIType.cli_oid:
         {
             int oid = buf.getInt();
             columns[i].SetValue(obj, (oid != 0) ? new Reference(oid) : null);
             break;
         }
         case Connection.CLIType.cli_rectangle:
             columns[i].SetValue(obj, buf.getRectangle());
             break;
         case Connection.CLIType.cli_asciiz:
             columns[i].SetValue(obj, buf.getString());
             break;
         case Connection.CLIType.cli_datetime:
             columns[i].SetValue(obj, new DateTime(((long)buf.getInt() & 0xFFFFFFFFL)*1000000));
             break;
         case Connection.CLIType.cli_array_of_int1:
         {
             len = buf.getInt();
             byte[] arr = new byte[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getByte();
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_int2:
         {
             len = buf.getInt();
             short[] arr = new short[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getShort();
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_int4:
         {
             len = buf.getInt();
             int[] arr = new int[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getInt();
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_int8:
         {
             len = buf.getInt();
             long[] arr = new long[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getLong();
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_real4:
         {
             len = buf.getInt();
             float[] arr = new float[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getFloat();
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_real8:
         {
             len = buf.getInt();
             double[] arr = new double[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getDouble();
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_bool:
         {
             len = buf.getInt();
             bool[] arr = new bool[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getByte() != 0;
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_oid:
         {
             len = buf.getInt();
             Reference[] arr = new Reference[len];
             for (j = 0; j < len; j++)
             {
                 int oid = buf.getInt();
                 arr[j] = oid != 0 ? new Reference(oid) : null;
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         case Connection.CLIType.cli_array_of_string:
         {
             len = buf.getInt();
             string[] arr = new string[len];
             for (j = 0; j < len; j++)
             {
                 arr[j] = buf.getAsciiz();
             }
             columns[i].SetValue(obj, arr);
             break;
         }
         default:
             throw new CliError("Unsupported type " + types[i]);
     }
     }
     return obj;
 }
Exemplo n.º 26
0
 internal void send(ComBuffer com)
 {
     int rc;
     com.end();
     for (int size = com.pos, offs = 0; size != 0; size -= rc, offs += rc) {
     int chunk = size > MaxSendParcelSize ? MaxSendParcelSize : size;
     rc = socket.Send(com.buf, offs, chunk, SocketFlags.None);
     if (rc <= 0) {
         throw new CliError("Socket write failed");
     }
     }
 }
Exemplo n.º 27
0
        internal object readObject(ComBuffer buf)
        {
            Object obj = constructor.Invoke(constructorParameters);
            int    i, j, n, len;

            for (i = 0, n = nColumns; i < n; i++)
            {
                Connection.CLIType type = (Connection.CLIType)buf.getByte();
                if (type != types[i])
                {
                    throw new CliError("Unexpected type of column: " + type
                                       + " instead of " + types[i]);
                }
                switch (types[i])
                {
                case Connection.CLIType.cli_int1:
                    columns[i].SetValue(obj, buf.getByte());
                    break;

                case Connection.CLIType.cli_int2:
                    columns[i].SetValue(obj, buf.getShort());
                    break;

                case Connection.CLIType.cli_int4:
                case Connection.CLIType.cli_autoincrement:
                    columns[i].SetValue(obj, buf.getInt());
                    break;

                case Connection.CLIType.cli_int8:
                    columns[i].SetValue(obj, buf.getLong());
                    break;

                case Connection.CLIType.cli_real4:
                    columns[i].SetValue(obj, buf.getFloat());
                    break;

                case Connection.CLIType.cli_real8:
                    columns[i].SetValue(obj, buf.getDouble());
                    break;

                case Connection.CLIType.cli_bool:
                    columns[i].SetValue(obj, buf.getByte() != 0);
                    break;

                case Connection.CLIType.cli_oid:
                {
                    int oid = buf.getInt();
                    columns[i].SetValue(obj, (oid != 0) ? new Reference(oid) : null);
                    break;
                }

                case Connection.CLIType.cli_rectangle:
                    columns[i].SetValue(obj, buf.getRectangle());
                    break;

                case Connection.CLIType.cli_asciiz:
                    columns[i].SetValue(obj, buf.getString());
                    break;

                case Connection.CLIType.cli_datetime:
                    columns[i].SetValue(obj, new DateTime(((long)buf.getInt() & 0xFFFFFFFFL) * 1000000));
                    break;

                case Connection.CLIType.cli_array_of_int1:
                {
                    len = buf.getInt();
                    byte[] arr = new byte[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getByte();
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_int2:
                {
                    len = buf.getInt();
                    short[] arr = new short[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getShort();
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_int4:
                {
                    len = buf.getInt();
                    int[] arr = new int[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getInt();
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_int8:
                {
                    len = buf.getInt();
                    long[] arr = new long[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getLong();
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_real4:
                {
                    len = buf.getInt();
                    float[] arr = new float[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getFloat();
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_real8:
                {
                    len = buf.getInt();
                    double[] arr = new double[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getDouble();
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_bool:
                {
                    len = buf.getInt();
                    bool[] arr = new bool[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getByte() != 0;
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_oid:
                {
                    len = buf.getInt();
                    Reference[] arr = new Reference[len];
                    for (j = 0; j < len; j++)
                    {
                        int oid = buf.getInt();
                        arr[j] = oid != 0 ? new Reference(oid) : null;
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                case Connection.CLIType.cli_array_of_string:
                {
                    len = buf.getInt();
                    string[] arr = new string[len];
                    for (j = 0; j < len; j++)
                    {
                        arr[j] = buf.getAsciiz();
                    }
                    columns[i].SetValue(obj, arr);
                    break;
                }

                default:
                    throw new CliError("Unsupported type " + types[i]);
                }
            }
            return(obj);
        }
Exemplo n.º 28
0
 internal int sendReceive(ComBuffer buf)
 {
     send(buf);
     receive(buf, 4);
     int rc = buf.getInt();
     if (rc < 0) {
     throw new CliError("Request failed with status " + rc);
     }
     return rc;
 }
Exemplo n.º 29
0
 /// <summary>
 /// Drop index
 /// </summary>
 /// <param name="tableName">name of the table</param>
 /// <param name="fieldName">name of the field</param>
 ///
 public void dropIndex(String tableName, String fieldName)
 {
     ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_alter_index);
     buf.putAsciiz(tableName);
     buf.putAsciiz(fieldName);
     buf.putByte(0);
     sendReceive(buf);
 }
Exemplo n.º 30
0
 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);
 }
Exemplo n.º 31
0
 /// <summary>
 /// Drop specified table
 /// </summary>
 /// <param name="tableName">name of the table</param>
 ///
 public void dropTable(String tableName)
 {
     ComBuffer buf = new ComBuffer(CLICommand.cli_cmd_drop_table);
     buf.putAsciiz(tableName);
     sendReceive(buf);
 }
Exemplo n.º 32
0
        /// <summary>
        /// Prepare (if needed) and execute select statement
        /// Only object set returned by the select for updated statement allows
        /// update and deletion of the objects.
        /// </summary>
        /// <param name="forUpdate">if cursor is opened in for update mode</param>
        /// <returns>object set with the selected objects</returns>
        ///
        public ObjectSet fetch(bool forUpdate)
        {
            int       i, n;
            ComBuffer buf;

            if (!prepared)
            {
                buf = new ComBuffer(Connection.CLICommand.cli_cmd_prepare_and_execute, stmtId);
                n   = tableDesc.nColumns;
                buf.putByte(nParams);
                buf.putByte(n);
                int  len     = stmtLen;
                bool addNull = false;
                if (len == 0 || stmt[len - 1] != 0)
                {
                    addNull = true;
                    len    += nParams;
                    buf.putShort(len + 1);
                }
                else
                {
                    len += nParams;
                    buf.putShort(len);
                }
                i = 0;
                Parameter p = parameters;
                do
                {
                    byte ch = stmt[i++];
                    buf.putByte(ch);
                    len -= 1;
                    if (ch == '\0')
                    {
                        if (len != 0)
                        {
                            if (p.type == Connection.CLIType.cli_undefined)
                            {
                                throw new CliError("Unbound parameter " + p.name);
                            }
                            buf.putByte((int)p.type);
                            p    = p.next;
                            len -= 1;
                        }
                    }
                } while (len != 0);
                if (addNull)
                {
                    buf.putByte('\0');
                }
                tableDesc.writeColumnDefs(buf);
            }
            else // statement was already prepared
            {
                buf = new ComBuffer(Connection.CLICommand.cli_cmd_execute, stmtId);
            }
            this.forUpdate = forUpdate;
            buf.putByte(forUpdate ? 1 : 0);
            for (Parameter p = parameters; p != null; p = p.next)
            {
                switch (p.type)
                {
                case Connection.CLIType.cli_oid:
                case Connection.CLIType.cli_int4:
                    buf.putInt(p.ivalue);
                    break;

                case Connection.CLIType.cli_int1:
                case Connection.CLIType.cli_bool:
                    buf.putByte((byte)p.ivalue);
                    break;

                case Connection.CLIType.cli_int2:
                    buf.putShort((short)p.ivalue);
                    break;

                case Connection.CLIType.cli_int8:
                    buf.putLong(p.lvalue);
                    break;

                case Connection.CLIType.cli_real4:
                    buf.putFloat(p.fvalue);
                    break;

                case Connection.CLIType.cli_real8:
                    buf.putDouble(p.dvalue);
                    break;

                case Connection.CLIType.cli_asciiz:
                    buf.putAsciiz(p.svalue);
                    break;
                }
            }
            prepared = true;
            return(new ObjectSet(this, con.sendReceive(buf)));
        }