/// <summary> /// /// </summary> public MonetDbDataReader(MapiHdl queryHandle, MonetDbConnection connection) { _queryHandle = queryHandle; _connHandle = connection.GetConnectionHandle(); Init(); }
/// <summary> /// /// </summary> public static void DieQueryError(MapiConnection connectionHandle, MapiHdl queryHandle) { if (queryHandle.Ptr == IntPtr.Zero || connectionHandle.Ptr == IntPtr.Zero || MapiLib.MapiError(connectionHandle).Ptr != IntPtr.Zero) { throw new MonetDbException(MapiLib.MapiErrorString(connectionHandle)); } }
/// <summary> /// Return an array of string pointers to the individual fields. /// A zero is returned upon encountering end of sequence or error. /// This can be analyzed in using mapi\_error(). /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static string[] MapiFetchFieldArray(MapiHdl hdl) { var pptr = CMapiLib.mapi_fetch_field_array(hdl.Ptr); var ptr = Marshal.ReadIntPtr(pptr); var exploded = new List <string>(); do { exploded.Add(Marshal.PtrToStringAnsi(ptr)); pptr = new IntPtr((int)pptr + IntPtr.Size); ptr = Marshal.ReadIntPtr(pptr); } while (ptr != IntPtr.Zero); return(exploded.ToArray()); }
/// <summary> /// Ship a previously prepared command to the back-end for execution. /// A single answer is pre-fetched to detect any runtime error. /// MOK is returned upon success. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiExecute(MapiHdl hdl) { return new MapiMsg(CMapiLib.mapi_execute(hdl.Ptr)); }
/// <summary> /// Write the error message obtained from mserver to a file. /// </summary> /// <param name="hdl"></param> /// <param name="fs"></param> /// <returns></returns> public static MapiMsg MapiExplainResult(MapiHdl hdl, FileStream fs) { return new MapiMsg(CMapiLib.mapi_explain_result(hdl.Ptr, fs.SafeFileHandle)); }
/// <summary> /// Similar to mapi\_execute but replacing the placeholders for the string values provided. /// </summary> /// <param name="hdl"></param> /// <param name="args"></param> /// <returns></returns> public static MapiMsg MapiExecuteArray(MapiHdl hdl, string[] args) { return(new MapiMsg(CMapiLib.mapi_execute_array(hdl.Ptr, args))); }
/// <summary> /// Submit a table of results to the library that can then subsequently be accessed /// as if it came from the server. columns is the number of columns of the result /// set and must be greater than zero. columnnames is a list of pointers to strings /// giving the names of the individual columns. Each pointer may be NULL and /// columnnames may be NULL if there are no names. tuplecount is the length /// (number of rows) of the result set. If tuplecount is less than zero, /// the number of rows is determined by a NULL pointer in the list of tuples /// pointers. tuples is a list of pointers to row values. Each row value is /// a list of pointers to strings giving the individual results. If one of /// these pointers is NULL it indicates a NULL/nil value. /// </summary> /// <param name="hdl"></param> /// <param name="columns"></param> /// <param name="columnnames"></param> /// <param name="columntypes"></param> /// <param name="columnlengths"></param> /// <param name="tuplecount"></param> /// <param name="tuples"></param> /// <returns></returns> public static MapiMsg MapiVirtualResult(MapiHdl hdl, int columns, string[] columnnames, string[] columntypes, int[] columnlengths, int tuplecount, string[][] tuples) { return(new MapiMsg(CMapiLib.mapi_virtual_result(hdl.Ptr, columns, columnnames, columntypes, columnlengths, tuplecount, tuples))); }
/// <summary> /// /// </summary> /// <param name="hdl"></param> /// <param name="fnr"></param> /// <returns></returns> public static string MapiGetType(MapiHdl hdl, int fnr) { return Marshal.PtrToStringAnsi(CMapiLib.mapi_get_type(hdl.Ptr, fnr)); }
/// <summary> /// Return a pointer to the last error message from the server. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static string MapiResultError(MapiHdl hdl) { return Marshal.PtrToStringAnsi(CMapiLib.mapi_result_error(hdl.Ptr)); }
/// <summary> /// All rows are cached at the client side first. Subsequent calls to mapi_fetch_row() will take /// the row from the cache. The number or rows cached is returned. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiFetchAllRows(MapiHdl hdl) { return(CMapiLib.mapi_fetch_all_rows(hdl.Ptr)); }
/// <summary> /// Terminate a query. This routine is used in the rare cases that consumption of the /// tuple stream produced should be prematurely terminated. It is automatically /// called when a new query using the same query handle is shipped to the database /// and when the query handle is closed with mapi_close_handle(). /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiFinish(MapiHdl hdl) { return new MapiMsg(CMapiLib.mapi_finish(hdl.Ptr)); }
/// <summary> /// Return the number of rows affected by a database update command such as SQL's INSERT/DELETE/UPDATE statements. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiRowsAffected(MapiHdl hdl) { return(CMapiLib.mapi_rows_affected(hdl.Ptr)); }
/// <summary> /// Retrieve a row from the server. The text retrieved is kept around in a buffer linked with the /// query handle from which selective fields can be extracted. It returns the number of fields /// recognized. A zero is returned upon encountering end of sequence or error. This can be /// analyzed in using mapi_error(). /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static int MapiFetchRow(MapiHdl hdl) { return(CMapiLib.mapi_fetch_row(hdl.Ptr)); }
/// <summary> /// /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiGetLastId(MapiHdl hdl) { return(CMapiLib.mapi_get_last_id(hdl.Ptr)); }
/// <summary> /// If possible, return the number of rows in the last select call. A -1 is returned if this information is not available. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiGetRowCount(MapiHdl hdl) { return(CMapiLib.mapi_get_row_count(hdl.Ptr)); }
/// <summary> /// Return the number of fields in the current row. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static int MapiGetFieldCount(MapiHdl hdl) { return(CMapiLib.mapi_get_field_count(hdl.Ptr)); }
/// <summary> /// Return a pointer a C-string representation of the value returned. /// A zero is returned upon encountering an error or when the database value is NULL; /// this can be analyzed in using mapi\_error(). /// </summary> /// <param name="hdl"></param> /// <param name="fnr"></param> /// <returns></returns> public static string MapiFetchField(MapiHdl hdl, int fnr) { return Marshal.PtrToStringAnsi(CMapiLib.mapi_fetch_field(hdl.Ptr, fnr)); }
/// <summary> /// Read the answer to a query and pass the results verbatim to a stream. /// The result is not analyzed or cached. /// </summary> /// <param name="hdl"></param> /// <param name="fs"></param> /// <returns></returns> public static int MapiQuickResponse(MapiHdl hdl, FileStream fs) { return(CMapiLib.mapi_quick_response(hdl.Ptr, fs.SafeFileHandle)); }
/// <summary> /// Reset the row pointer to the first line in the cache. This need not be a tuple. /// This is mostly used in combination with fetching all tuples at once. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiFetchReset(MapiHdl hdl) { return new MapiMsg(CMapiLib.mapi_fetch_reset(hdl.Ptr)); }
/// <summary> /// Reset the row pointer to the requested row number. If whence is MAPI_SEEK_SET (0), /// rownr is the absolute row number (0 being the first row); if whence is /// MAPI_SEEK_CUR (1), rownr is relative to the current row; if whence is /// MAPI\_SEEK\_END (2), rownr is relative to the last row. /// </summary> /// <param name="hdl"></param> /// <param name="rownr"></param> /// <param name="whence"></param> /// <returns></returns> public static MapiMsg MapiSeekRow(MapiHdl hdl, long rownr, int whence) { return(new MapiMsg(CMapiLib.mapi_seek_row(hdl.Ptr, rownr, whence))); }
/// <summary> /// /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiGetLastId(MapiHdl hdl) { return CMapiLib.mapi_get_last_id(hdl.Ptr); }
/// <summary> /// Reset the row pointer to the first line in the cache. This need not be a tuple. /// This is mostly used in combination with fetching all tuples at once. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiFetchReset(MapiHdl hdl) { return(new MapiMsg(CMapiLib.mapi_fetch_reset(hdl.Ptr))); }
/// <summary> /// Send the Command to the database server represented by hdl, /// reusing the handle from a previous query. If Command is zero it /// takes the last query string kept around. The command response is /// buffered for consumption, e.g. mapi_fetch_row(). /// </summary> /// <param name="hdl"></param> /// <param name="command"></param> /// <returns></returns> public static MapiMsg MapiQueryHandle(MapiHdl hdl, string command) { return new MapiMsg(CMapiLib.mapi_query_handle(hdl.Ptr, command)); }
/// <summary> /// Make room in the cache by shuffling percentage tuples out of the cache. /// It is sometimes handy to do so, for example, when your application is stream-based /// and you process each tuple as it arrives and still need a limited look-back. /// This percentage can be set between 0 to 100. Making shuffle= 100% (default) /// leads to paging behavior, while shuffle==1 leads to a sliding window over a /// tuple stream with 1% refreshing. /// </summary> /// <param name="hdl"></param> /// <param name="percentage"></param> /// <returns></returns> public static MapiMsg MapiCacheShuffle(MapiHdl hdl, int percentage) { return new MapiMsg(CMapiLib.mapi_cache_shuffle(hdl.Ptr, percentage)); }
/// <summary> /// Reset the row pointer to the requested row number. If whence is MAPI_SEEK_SET (0), /// rownr is the absolute row number (0 being the first row); if whence is /// MAPI_SEEK_CUR (1), rownr is relative to the current row; if whence is /// MAPI\_SEEK\_END (2), rownr is relative to the last row. /// </summary> /// <param name="hdl"></param> /// <param name="rownr"></param> /// <param name="whence"></param> /// <returns></returns> public static MapiMsg MapiSeekRow(MapiHdl hdl, long rownr, int whence) { return new MapiMsg(CMapiLib.mapi_seek_row(hdl.Ptr, rownr, whence)); }
/// <summary> /// /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiClearParams(MapiHdl hdl) { return new MapiMsg(CMapiLib.mapi_clear_params(hdl.Ptr)); }
/// <summary> /// Send the Command to the database server represented by hdl, /// reusing the handle from a previous query. If Command is zero it /// takes the last query string kept around. The command response is /// buffered for consumption, e.g. mapi_fetch_row(). /// </summary> /// <param name="hdl"></param> /// <param name="command"></param> /// <returns></returns> public static MapiMsg MapiQueryHandle(MapiHdl hdl, string command) { return(new MapiMsg(CMapiLib.mapi_query_handle(hdl.Ptr, command))); }
/// <summary> /// Terminate a query. This routine is used in the rare cases that consumption of the /// tuple stream produced should be prematurely terminated. It is automatically /// called when a new query using the same query handle is shipped to the database /// and when the query handle is closed with mapi_close_handle(). /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiFinish(MapiHdl hdl) { return(new MapiMsg(CMapiLib.mapi_finish(hdl.Ptr))); }
/// <summary> /// Clear all field bindings. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiClearBindings(MapiHdl hdl) { return new MapiMsg(CMapiLib.mapi_clear_bindings(hdl.Ptr)); }
/// <summary> /// Return a pointer a C-string representation of the value returned. /// A zero is returned upon encountering an error or when the database value is NULL; /// this can be analyzed in using mapi\_error(). /// </summary> /// <param name="hdl"></param> /// <param name="fnr"></param> /// <returns></returns> public static string MapiFetchField(MapiHdl hdl, int fnr) { return(Marshal.PtrToStringAnsi(CMapiLib.mapi_fetch_field(hdl.Ptr, fnr))); }
/// <summary> /// Close query handle and free resources /// </summary> /// <param name="hdl">Query handle</param> /// <returns></returns> public static MapiMsg MapiCloseHandle(MapiHdl hdl) { return new MapiMsg(CMapiLib.mapi_close_handle(hdl.Ptr)); }
/// <summary> /// Go to the next result set, discarding the rest of the output of the current result set. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiNextResult(MapiHdl hdl) { return(new MapiMsg(CMapiLib.mapi_next_result(hdl.Ptr))); }
/// <summary> /// Similar to mapi\_execute but replacing the placeholders for the string values provided. /// </summary> /// <param name="hdl"></param> /// <param name="args"></param> /// <returns></returns> public static MapiMsg MapiExecuteArray(MapiHdl hdl, string[] args) { return new MapiMsg(CMapiLib.mapi_execute_array(hdl.Ptr, args)); }
/// <summary> /// Return a pointer to the last error message from the server. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static string MapiResultError(MapiHdl hdl) { return(Marshal.PtrToStringAnsi(CMapiLib.mapi_result_error(hdl.Ptr))); }
/// <summary> /// All rows are cached at the client side first. Subsequent calls to mapi_fetch_row() will take /// the row from the cache. The number or rows cached is returned. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiFetchAllRows(MapiHdl hdl) { return CMapiLib.mapi_fetch_all_rows(hdl.Ptr); }
/// <summary> /// Write the error message obtained from mserver to a file. /// </summary> /// <param name="hdl"></param> /// <param name="fs"></param> /// <returns></returns> public static MapiMsg MapiExplainResult(MapiHdl hdl, FileStream fs) { return(new MapiMsg(CMapiLib.mapi_explain_result(hdl.Ptr, fs.SafeFileHandle))); }
/// <summary> /// Return an array of string pointers to the individual fields. /// A zero is returned upon encountering end of sequence or error. /// This can be analyzed in using mapi\_error(). /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static string[] MapiFetchFieldArray(MapiHdl hdl) { var pptr = CMapiLib.mapi_fetch_field_array(hdl.Ptr); var ptr = Marshal.ReadIntPtr(pptr); var exploded = new List<string>(); do { exploded.Add(Marshal.PtrToStringAnsi(ptr)); pptr = new IntPtr((int)pptr + IntPtr.Size); ptr = Marshal.ReadIntPtr(pptr); } while (ptr != IntPtr.Zero); return exploded.ToArray(); }
/// <summary> /// Bind a string variable with a field in the return table. /// Upon a successful subsequent mapi_fetch_row() the indicated field /// is stored in the space pointed to by val. Returns an error if /// the field identified does not exist. /// </summary> /// <param name="hdl"></param> /// <param name="fldnr"></param> /// <param name="val"></param> /// <returns></returns> public static MapiMsg MapiBind(MapiHdl hdl, int fldnr, string[] val) { return(new MapiMsg(CMapiLib.mapi_bind(hdl.Ptr, fldnr, val))); }
/// <summary> /// Retrieve a row from the server. The text retrieved is kept around in a buffer linked with the /// query handle from which selective fields can be extracted. It returns the number of fields /// recognized. A zero is returned upon encountering end of sequence or error. This can be /// analyzed in using mapi_error(). /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static int MapiFetchRow(MapiHdl hdl) { return CMapiLib.mapi_fetch_row(hdl.Ptr); }
/// <summary> /// Clear all field bindings. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiClearBindings(MapiHdl hdl) { return(new MapiMsg(CMapiLib.mapi_clear_bindings(hdl.Ptr))); }
/// <summary> /// Return the number of fields in the current row. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static int MapiGetFieldCount(MapiHdl hdl) { return CMapiLib.mapi_get_field_count(hdl.Ptr); }
/// <summary> /// /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiClearParams(MapiHdl hdl) { return(new MapiMsg(CMapiLib.mapi_clear_params(hdl.Ptr))); }
/// <summary> /// If possible, return the number of rows in the last select call. A -1 is returned if this information is not available. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiGetRowCount(MapiHdl hdl) { return CMapiLib.mapi_get_row_count(hdl.Ptr); }
/// <summary> /// Make room in the cache by shuffling percentage tuples out of the cache. /// It is sometimes handy to do so, for example, when your application is stream-based /// and you process each tuple as it arrives and still need a limited look-back. /// This percentage can be set between 0 to 100. Making shuffle= 100% (default) /// leads to paging behavior, while shuffle==1 leads to a sliding window over a /// tuple stream with 1% refreshing. /// </summary> /// <param name="hdl"></param> /// <param name="percentage"></param> /// <returns></returns> public static MapiMsg MapiCacheShuffle(MapiHdl hdl, int percentage) { return(new MapiMsg(CMapiLib.mapi_cache_shuffle(hdl.Ptr, percentage))); }
/// <summary> /// Go to the next result set, discarding the rest of the output of the current result set. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiNextResult(MapiHdl hdl) { return new MapiMsg(CMapiLib.mapi_next_result(hdl.Ptr)); }
/// <summary> /// Forcefully shuffle the cache making room for new rows. It ignores the read counter, so rows may be lost. /// </summary> /// <param name="hdl"></param> /// <param name="percentage"></param> /// <returns></returns> public static MapiMsg MapiCacheFreeup(MapiHdl hdl, int percentage) { return(new MapiMsg(CMapiLib.mapi_cache_freeup(hdl.Ptr, percentage))); }
/// <summary> /// Read the answer to a query and pass the results verbatim to a stream. /// The result is not analyzed or cached. /// </summary> /// <param name="hdl"></param> /// <param name="fs"></param> /// <returns></returns> public static int MapiQuickResponse(MapiHdl hdl, FileStream fs) { return CMapiLib.mapi_quick_response(hdl.Ptr, fs.SafeFileHandle); }
/// <summary> /// /// </summary> /// <param name="hdl"></param> /// <param name="fnr"></param> /// <returns></returns> public static string MapiGetTable(MapiHdl hdl, int fnr) { return(Marshal.PtrToStringAnsi(CMapiLib.mapi_get_table(hdl.Ptr, fnr))); }
/// <summary> /// Return the number of rows affected by a database update command such as SQL's INSERT/DELETE/UPDATE statements. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static long MapiRowsAffected(MapiHdl hdl) { return CMapiLib.mapi_rows_affected(hdl.Ptr); }
/// <summary> /// /// </summary> /// <param name="queryHandle"></param> public static void CloseQueryHandle(MapiHdl queryHandle) { MapiLib.MapiFinish(queryHandle); MapiLib.MapiCloseHandle(queryHandle); }
/// <summary> /// Submit a table of results to the library that can then subsequently be accessed /// as if it came from the server. columns is the number of columns of the result /// set and must be greater than zero. columnnames is a list of pointers to strings /// giving the names of the individual columns. Each pointer may be NULL and /// columnnames may be NULL if there are no names. tuplecount is the length /// (number of rows) of the result set. If tuplecount is less than zero, /// the number of rows is determined by a NULL pointer in the list of tuples /// pointers. tuples is a list of pointers to row values. Each row value is /// a list of pointers to strings giving the individual results. If one of /// these pointers is NULL it indicates a NULL/nil value. /// </summary> /// <param name="hdl"></param> /// <param name="columns"></param> /// <param name="columnnames"></param> /// <param name="columntypes"></param> /// <param name="columnlengths"></param> /// <param name="tuplecount"></param> /// <param name="tuples"></param> /// <returns></returns> public static MapiMsg MapiVirtualResult(MapiHdl hdl, int columns, string[] columnnames, string[] columntypes, int[] columnlengths, int tuplecount, string[][] tuples) { return new MapiMsg(CMapiLib.mapi_virtual_result(hdl.Ptr, columns, columnnames, columntypes, columnlengths, tuplecount, tuples)); }
/// <summary> /// Ship a previously prepared command to the back-end for execution. /// A single answer is pre-fetched to detect any runtime error. /// MOK is returned upon success. /// </summary> /// <param name="hdl"></param> /// <returns></returns> public static MapiMsg MapiExecute(MapiHdl hdl) { return(new MapiMsg(CMapiLib.mapi_execute(hdl.Ptr))); }
/// <summary> /// Bind a string variable with a field in the return table. /// Upon a successful subsequent mapi_fetch_row() the indicated field /// is stored in the space pointed to by val. Returns an error if /// the field identified does not exist. /// </summary> /// <param name="hdl"></param> /// <param name="fldnr"></param> /// <param name="val"></param> /// <returns></returns> public static MapiMsg MapiBind(MapiHdl hdl, int fldnr, string[] val) { return new MapiMsg(CMapiLib.mapi_bind(hdl.Ptr, fldnr, val)); }
/// <summary> /// Forcefully shuffle the cache making room for new rows. It ignores the read counter, so rows may be lost. /// </summary> /// <param name="hdl"></param> /// <param name="percentage"></param> /// <returns></returns> public static MapiMsg MapiCacheFreeup(MapiHdl hdl, int percentage) { return new MapiMsg(CMapiLib.mapi_cache_freeup(hdl.Ptr, percentage)); }
/// <summary> /// Close query handle and free resources /// </summary> /// <param name="hdl">Query handle</param> /// <returns></returns> public static MapiMsg MapiCloseHandle(MapiHdl hdl) { return(new MapiMsg(CMapiLib.mapi_close_handle(hdl.Ptr))); }