Exemplo n.º 1
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.º 2
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.º 3
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.º 4
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]);
                }
            }
        }