public static int cci_prepare(CUBRIDConnection conn_handle, string sql_stmt, ref T_CCI_ERROR err_buf) { int ret = cci_set_holdability(conn_handle.Conection, 0); if (ret < 0) { return(ret); } byte[] sql = conn_handle.GetEncoding().GetBytes(sql_stmt); string trimed_stmt = new string(sql_stmt.ToCharArray() .Where(c => !Char.IsWhiteSpace(c)) .ToArray()); if ((trimed_stmt.Substring(0, 6).ToLower() == "?=call") || (trimed_stmt.Substring(0, 4).ToLower() == "call")) { return(cci_prepare( conn_handle.Conection, sql, (char)T_CCI_PREPARE_FLAG.CCI_PREPARE_CALL, ref err_buf)); } else { return(cci_prepare( conn_handle.Conection, sql, (char)(T_CCI_PREPARE_FLAG.CCI_PREPARE_INCLUDE_OID | T_CCI_PREPARE_FLAG.CCI_PREPARE_UPDATABLE), ref err_buf)); } }
/// <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; }
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); }
/// <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); }
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); }
/// <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); }
/// <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); }
/// <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); }
/// <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); }
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; }
public static int cci_schema_info(CUBRIDConnection con, T_CCI_SCH_TYPE type, string class_name, string attr_name, char flag, ref T_CCI_ERROR err_buf) { return(cci_schema_info(con.Conection, type, class_name, attr_name, flag, ref err_buf)); }
public static extern int cci_schema_info(int conn_handle, T_CCI_SCH_TYPE type, string class_name, string attr_name, char flag, ref T_CCI_ERROR err_buf);
public static int cci_set_db_parameter(int con_handle, T_CCI_DB_PARAM param_name, int value, ref T_CCI_ERROR err_buf) { return cci_set_db_parameter(con_handle, param_name, ref value, ref err_buf); }
public static extern int cci_clob_new(int con_h_id, ref IntPtr clob, ref T_CCI_ERROR err_buf);
public static extern int cci_col_set_add(int mapped_conn_id, string oid_str, string col_attr, string value, ref T_CCI_ERROR err_buf);
public static extern int cci_col_size(int mapped_conn_id, string oid_str, string col_attr, ref int col_size, ref T_CCI_ERROR err_buf);
/// <summary> /// Gets the LOB content as String. /// </summary> /// <param name="pos"> The position. </param> /// <param name="length"> The length. </param> /// <returns> </returns> public string GetString(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_clob_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 System.Text.Encoding.Default.GetString(buf); }
/// <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; }
/// <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 (handle); if (handle > 0) { CciInterface.cci_close_req_handle (handle); handle = 0; } return ret; }
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 (handle); dataReader = new CUBRIDDataReader (this, handle, ret, columnInfos, ret); return dataReader; }
/// <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; }
/// <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; }
public static extern int cci_cursor(int mapped_stmt_id, int offset, CCICursorPosition origin, ref T_CCI_ERROR err_buf);
public static extern int cci_col_seq_drop(int mapped_conn_id, string oid_str, string col_attr, int index, ref T_CCI_ERROR err_buf);
public static extern int cci_clob_read(int con_h_id, IntPtr clob, UInt64 start_pos, int length, byte[] buf, ref T_CCI_ERROR err_buf);
public static extern int cci_connect_with_url_ex(string url, string db_user, string db_password, ref T_CCI_ERROR err_buf);
public static extern int cci_execute_batch_internal(int conn_handle, int num_sql_stmt, string[] sql_stmt, ref IntPtr query_result, ref T_CCI_ERROR err_buf);
public static extern int cci_oid_get_class_name(int mapped_conn_id, string oid_str, byte[] out_buf, int out_buf_size, ref T_CCI_ERROR err_buf);
public static int cci_execute_batch(int conn_handle, string[] sql_stmt, ref T_CCI_QUERY_RESULT[] query_result, ref T_CCI_ERROR err_buf) { IntPtr qr_ptr = IntPtr.Zero; int n_executed = cci_execute_batch_internal(conn_handle, sql_stmt.Length, sql_stmt, ref qr_ptr, ref err_buf); if (n_executed < 0) { query_result = null; } else { query_result = new T_CCI_QUERY_RESULT[n_executed]; for (int i = 0; i < n_executed; i++) { T_CCI_QUERY_RESULT tmp = (T_CCI_QUERY_RESULT) Marshal.PtrToStructure((IntPtr)((UInt32)qr_ptr + i * Marshal.SizeOf(typeof(T_CCI_QUERY_RESULT))), typeof(T_CCI_QUERY_RESULT)); query_result[i] = tmp; } cci_query_result_free(qr_ptr, n_executed); } return n_executed; }
public static extern int cci_disconnect(int mapped_conn_id, ref T_CCI_ERROR err_buf);
public static int cci_execute_batch(int conn_handle, string[] sql_stmt, ref T_CCI_QUERY_RESULT[] query_result, ref T_CCI_ERROR err_buf) { IntPtr qr_ptr = IntPtr.Zero; int n_executed = cci_execute_batch_internal(conn_handle, sql_stmt.Length, sql_stmt, ref qr_ptr, ref err_buf); if (n_executed < 0) { query_result = null; } else { query_result = new T_CCI_QUERY_RESULT[n_executed]; for (int i = 0; i < n_executed; i++) { T_CCI_QUERY_RESULT tmp; IntPtr data_ptr; data_ptr = Utils.AddIntPtr(qr_ptr, i * Marshal.SizeOf(typeof(T_CCI_QUERY_RESULT))); tmp = (T_CCI_QUERY_RESULT)Marshal.PtrToStructure(data_ptr, typeof(T_CCI_QUERY_RESULT)); query_result[i] = tmp; } cci_query_result_free(qr_ptr, n_executed); } return(n_executed); }
/// <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(handle); currentRow = 0; resultTuple = new ResultTuple(columnMetaData.Length); commandBehavior = CommandBehavior.Default; bRet = true; } return bRet; }
public static extern int cci_prepare(int conn_handle, byte[] sql_stmt, char flag, ref T_CCI_ERROR err_buf);
public static extern int cci_prepare(int conn_handle, string sql_stmt, char flag, ref T_CCI_ERROR err_buf);
public static extern int cci_execute(int req_handle, char flag, int max_col_size, ref T_CCI_ERROR err_buf);
public static extern int cci_fetch(int mapped_stmt_id, ref T_CCI_ERROR err_buf);
public static extern int cci_clob_write(int con_h_id, IntPtr clob, UInt64 start_pos, int length, string buf, ref T_CCI_ERROR err_buf);
public static extern int cci_set_db_parameter(int con_handle, T_CCI_DB_PARAM param_name, ref int value, ref T_CCI_ERROR err_buf);
public static extern int cci_end_tran(int con_handle, char type, ref T_CCI_ERROR err_buf);
public static int cci_set_db_parameter(int con_handle, T_CCI_DB_PARAM param_name, int value, ref T_CCI_ERROR err_buf) { return(cci_set_db_parameter(con_handle, param_name, ref value, ref err_buf)); }
public static extern int cci_next_result(int req_handle, ref T_CCI_ERROR err_buf);
public static int cci_schema_info(CUBRIDConnection con, T_CCI_SCH_TYPE type, string class_name, string attr_name, char flag, ref T_CCI_ERROR err_buf) { return cci_schema_info(con.Conection, type, class_name, attr_name, flag, ref err_buf); }
public static int cci_prepare(CUBRIDConnection conn_handle, string sql_stmt, ref T_CCI_ERROR err_buf) { int ret = cci_set_holdability(conn_handle.Conection,0); if (ret < 0) { return ret; } sql_stmt = Encoding.Default.GetString(conn_handle.GetEncoding().GetBytes(sql_stmt)); return cci_prepare( conn_handle.Conection, sql_stmt, (char)(T_CCI_PREPARE_FLAG.CCI_PREPARE_INCLUDE_OID| T_CCI_PREPARE_FLAG.CCI_PREPARE_UPDATABLE), ref err_buf); }