internal T_CCI_ERROR_CODE ReadResultTuple()
        {
            resultTuple.Index = currentRow - 1;
            resultTuple.Oid   = null;
            T_CCI_ERROR err = new T_CCI_ERROR();

            int res = CciInterface.cci_cursor(handle, 1, CCICursorPosition.CCI_CURSOR_CURRENT, ref err);

            if (res == (int)T_CCI_ERROR_CODE.CCI_ER_NO_MORE_DATA)
            {
                return(T_CCI_ERROR_CODE.CCI_ER_NO_MORE_DATA);
            }
            if (res < 0)
            {
                throw new CUBRIDException(err.err_msg);
            }

            if ((res = CciInterface.cci_fetch(handle, ref err)) < 0)
            {
                throw new CUBRIDException(err.err_msg);
            }

            for (int i = 1; i <= columnMetaData.Length; i++)
            {
                res = CciInterface.cci_get_data(resultTuple, handle, i, (int)columnMetaData[i - 1].Type, conn);
                if (columnMetaData[i - 1].Name == null)
                {
                    columnMetaData[i - 1].Name = i.ToString();
                }
                resultTuple[columnMetaData[i - 1].Name] = resultTuple[i - 1];
            }
            return(T_CCI_ERROR_CODE.CCI_ER_NO_ERROR);
        }
Example #2
0
        /// <summary>
        ///   Creates a prepared (or compiled) version of the command on the data source.
        /// </summary>
        public override void Prepare()
        {
            if (conn == null)
            {
                throw new InvalidOperationException(Utils.GetStr(MsgId.TheConnectionPropertyHasNotBeenSet));
            }

            if (conn.State != ConnectionState.Open)
            {
                throw new InvalidOperationException(Utils.GetStr(MsgId.TheConnectionIsNotOpen));
            }

            if (cmdText == null || cmdText.Trim().Length == 0)
            {
                return;
            }

            for (int i = 0; i < paramCollection.Count; i++)
            {
                cmdText = cmdText.Replace(paramCollection[i].ParameterName, "?");
            }
            T_CCI_ERROR err = new T_CCI_ERROR();

            handle = CciInterface.cci_prepare(conn, cmdText, ref err);
            if (handle < 0)
            {
                throw new InvalidOperationException(err.err_msg);
            }

            isPrepared = true;
        }
Example #3
0
        /// <summary>
        /// Close Command
        /// </summary>
        public void Close()
        {
            if (conn.State == ConnectionState.Closed)
            {
                return;
            }

            CciInterface.cci_close_req_handle(handle);
            handle = 0;
        }
Example #4
0
        /// <summary>
        ///   Executes a SQL statement against a connection object.
        /// </summary>
        /// <returns> The number of rows affected. </returns>
        public override int ExecuteNonQuery()
        {
            BindParameters();

            T_CCI_ERROR err = new T_CCI_ERROR();
            int         ret = CciInterface.cci_execute(handle, (char)CCIExecutionOption.CCI_EXEC_QUERY_ALL, 0, ref err);

            if (ret < 0)
            {
                throw new CUBRIDException(err.err_msg);
            }

            columnInfos = CciInterface.cci_get_result_info(conn, handle);

            if (this.Parameters.Count > 0)
            {
                if (this.GetOutModeParameterCount() == 0 || columnInfos == null)
                {
                    CciInterface.cci_close_req_handle(handle);
                    handle = 0;

                    return(ret);
                }

                if ((CciInterface.cci_cursor(handle, 1, CCICursorPosition.CCI_CURSOR_FIRST, ref err)) < 0)
                {
                    throw new CUBRIDException(err.err_msg);
                }

                if ((CciInterface.cci_fetch(handle, ref err)) < 0)
                {
                    throw new CUBRIDException(err.err_msg);
                }

                for (int i = 1; i <= this.Parameters.Count; i++)
                {
                    if (this.Parameters[i - 1].Direction == ParameterDirection.InputOutput || this.Parameters[i - 1].Direction == ParameterDirection.Output)
                    {
                        object value = new object();
                        CciInterface.cci_get_value(conn, i, Parameters[i - 1].CUBRIDDataType, ref value);
                        Parameters[i - 1].Value = value;
                    }
                }
            }

            CciInterface.cci_close_req_handle(handle);
            handle = 0;

            return(ret);
        }
Example #5
0
        internal CUBRIDDataReader ExecuteInternal()
        {
            T_CCI_ERROR err = new T_CCI_ERROR();
            int         ret = CciInterface.cci_execute(handle, (char)CCIExecutionOption.CCI_EXEC_QUERY_ALL, 0, ref err);

            if (ret < 0)
            {
                throw new CUBRIDException(err.err_msg);
            }

            //T_CCI_COL_INFO res;
            columnInfos = CciInterface.cci_get_result_info(conn, handle);

            dataReader = new CUBRIDDataReader(this, handle, ret, columnInfos, ret);

            return(dataReader);
        }
Example #6
0
        /// <summary>
        ///   Sets the LOB content as bytes array.
        /// </summary>
        /// <param name="pos"> The position. </param>
        /// <param name="bytes"> The bytes array. </param>
        /// <returns> The number of written bytes </returns>
        public long SetBytes(ulong pos, byte[] bytes)
        {
            int         len = bytes.Length;
            T_CCI_ERROR err = new T_CCI_ERROR();

            pos--;

            int res = CciInterface.cci_blob_write(
                connection.Conection, packedLobHandle,
                pos, bytes.GetLength(0), bytes, ref err);

            if (res < 0)
            {
                throw new CUBRIDException(err.err_code, err.err_msg);
            }

            return(res);
        }
Example #7
0
        /// <summary>
        ///   Sets the LOB content from String.
        /// </summary>
        /// <param name="pos"> The position. </param>
        /// <param name="str"> The string. </param>
        /// <returns> </returns>
        public long SetString(ulong pos, string str)
        {
            int         len = str.Length;
            T_CCI_ERROR err = new T_CCI_ERROR();

            pos--;

            int res = CciInterface.cci_clob_write(
                connection.Conection, packedLobHandle,
                pos, str.Length, str, ref err);

            if (res < 0)
            {
                throw new CUBRIDException(err.err_code, err.err_msg);
            }

            return(res);
        }
Example #8
0
        private void BindParameters()
        {
            if (isPrepared == false)
            {
                Prepare();
            }

            //TODO Verify if other initializations are required
            if (parameters == null && paramCollection.Count > 0)
            {
                //Initialize parameters collection
                parameters = new CUBRIDParameter[paramCollection.Count];
            }

            for (int i = 0; i < paramCollection.Count; i++)
            {
                parameters[i] = paramCollection[i];
                if (this.Parameters[i].Direction == ParameterDirection.Input)
                {
                    if (parameters[i].InnerCUBRIDDataType == CUBRIDDataType.CCI_U_TYPE_BLOB ||
                        parameters[i].InnerCUBRIDDataType == CUBRIDDataType.CCI_U_TYPE_CLOB)
                    {
                        isPrepared = false;
                        throw new CUBRIDException("Not implemented");
                    }
                    int err_code = CciInterface.cci_bind_param
                                       (conn, handle, i + 1, T_CCI_A_TYPE.CCI_A_TYPE_STR, parameters[i], CUBRIDDataType.CCI_U_TYPE_STRING, (char)0);

                    if (err_code < 0)
                    {
                        isPrepared = false;
                        throw new CUBRIDException(err_code);
                    }
                }
                else
                {
                    CciInterface.cci_register_out_param(handle, i + 1, T_CCI_A_TYPE.CCI_A_TYPE_STR);
                }
            }

            //TODO Verify if these initializations are required
            bindCount  = paramCollection.Count;
            isPrepared = false;
        }
Example #9
0
        /// <summary>
        ///   Gets the LOB content as bytes array.
        /// </summary>
        /// <param name="pos"> The position. </param>
        /// <param name="length"> The length. </param>
        /// <returns> A buffer containing the requested data </returns>
        public byte[] GetBytes(long pos, int length)
        {
            ulong lob_size = CciInterface.cci_blob_size(packedLobHandle);

            if (lob_size < 0)
            {
                throw new CUBRIDException("Get lob size failed.");
            }
            pos--;
            lob_size = (lob_size - (ulong)pos < (ulong)length) ? lob_size - (ulong)pos : (ulong)length;

            byte[]      buf = new byte[lob_size];
            T_CCI_ERROR err = new T_CCI_ERROR();
            int         res = CciInterface.cci_blob_read(connection.Conection, packedLobHandle, (ulong)pos, (int)lob_size, buf, ref err);

            if (res < 0)
            {
                throw new CUBRIDException(err.err_code, err.err_msg);
            }
            return(buf);
        }
Example #10
0
        /// <summary>
        ///   Advances the reader to the next result when reading the results of a batch of statements.
        /// </summary>
        /// <returns> true if there are more result sets; otherwise false. </returns>
        public override bool NextResult()
        {
            if (isClosed)
            {
                throw new CUBRIDException(Utils.GetStr(MsgId.InvalidAttemptToReadDataWhenReaderNotOpen));
            }

            T_CCI_ERROR err  = new T_CCI_ERROR();
            bool        bRet = false;

            resultCount = CciInterface.cci_next_result(handle, ref err);
            if (resultCount >= 0)
            {
                columnMetaData  = CciInterface.cci_get_result_info(conn, handle);
                currentRow      = 0;
                resultTuple     = new ResultTuple(columnMetaData.Length);
                commandBehavior = CommandBehavior.Default;
                bRet            = true;
            }

            return(bRet);
        }
        /// <summary>
        ///   Get the schemas of the foreign keys satisfying the foreign key filter.
        /// </summary>
        /// <param name="filters"> The foreign key filter, the value is {"table name pattern", "foreign key name pattern"}.<para/>
        /// If the table name pattern is null, the default "%" is used. If the foreign key name pattern is null, the default "" is used. </param>
        /// <returns>A <see cref="DataTable" /> that contains foreign key schema information and contains <para/>
        /// columns {"PKTABLE_NAME", "PKCOLUMN_NAME", "FKTABLE_NAME", "FKCOLUMN_NAME", "KEY_SEQ", "UPDATE_ACTION", "DELETE_ACTION", "FK_NAME", "PK_NAME"} </returns>
        public DataTable GetForeignKeys(string[] filters)
        {
            if (filters == null)
            {
                throw new ArgumentNullException(Utils.GetStr(MsgId.NoFiltersSpecified));
            }

            if (filters.Length > 2)
            {
                throw new ArgumentException(Utils.GetStr(MsgId.IncorrectNumberOfFilters));
            }

            string tableName = filters[0];
            string keyName   = "";

            if (filters.Length > 1)
            {
                keyName = filters[1];
            }

            T_CCI_ERROR err    = new T_CCI_ERROR();
            int         handle = CciInterface.cci_schema_info(conn, T_CCI_SCH_TYPE.CCI_SCH_IMPORTED_KEYS, tableName, keyName, (char)0, ref err);

            if (handle < 0)
            {
                throw new CUBRIDException(err.err_msg);
            }

            ColumnMetaData[] columnInfos = CciInterface.cci_get_result_info(conn, handle);
            CUBRIDCommand    command     = new CUBRIDCommand(null, conn);
            CUBRIDDataReader reader      = new CUBRIDDataReader(command, handle, columnInfos.Length, columnInfos, columnInfos.Length);

            DataTable dt = new DataTable("ForeignKeys");

            dt.Columns.Add("PKTABLE_NAME", typeof(string));
            dt.Columns.Add("PKCOLUMN_NAME", typeof(string));
            dt.Columns.Add("FKTABLE_NAME", typeof(string));
            dt.Columns.Add("FKCOLUMN_NAME", typeof(string));
            dt.Columns.Add("KEY_SEQ", typeof(short));
            dt.Columns.Add("UPDATE_ACTION", typeof(short));
            dt.Columns.Add("DELETE_ACTION", typeof(short));
            dt.Columns.Add("FK_NAME", typeof(string));
            dt.Columns.Add("PK_NAME", typeof(string));

            while (reader.Read())
            {
                DataRow row = dt.NewRow();

                row["PKTABLE_NAME"]  = reader.GetString(0);
                row["PKCOLUMN_NAME"] = reader.GetString(1);
                row["FKTABLE_NAME"]  = reader.GetString(2);
                row["FKCOLUMN_NAME"] = reader.GetString(3);
                row["KEY_SEQ"]       = reader.GetString(4);
                row["UPDATE_ACTION"] = reader.GetString(5);
                row["DELETE_ACTION"] = reader.GetString(6);
                row["FK_NAME"]       = reader.GetString(7);
                row["PK_NAME"]       = reader.GetString(8);

                dt.Rows.Add(row);
            }
            return(dt);
        }