/// <summary> /// /// </summary> public MonetDbDataReader(MapiHdl queryHandle, MonetDbConnection connection) { _queryHandle = queryHandle; _connHandle = connection.GetConnectionHandle(); Init(); }
/// <summary> /// /// </summary> /// <param name="connectionHandle"></param> /// <exception cref="MonetDbException"></exception> public static void DieConnectionError(MapiConnection connectionHandle) { if (connectionHandle.Ptr == IntPtr.Zero || MapiLib.MapiError(connectionHandle).Ptr != IntPtr.Zero) { throw new MonetDbException(MapiLib.MapiErrorString(connectionHandle)); } }
/// <summary> /// /// </summary> /// <param name="connection"></param> /// <param name="query"></param> /// <returns></returns> /// <exception cref="MonetDbException"></exception> public static MapiHdl GetQueryHandle(MapiConnection connection, string query) { var queryHandle = MapiLib.MapiQuery(connection, query); DieQueryError(connection, queryHandle); return(queryHandle); }
/// <summary> /// Return a list of accessible tables fields. This can also be obtained by /// inspecting the field descriptor returned by mapi_fetch_field(). /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string[] MapiFields(MapiConnection mid) { var pptr = CMapiLib.mapi_fields(mid.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> /// Send the Command to the database server represented by mid. /// This function returns a query handle with which the results of the /// query can be retrieved. The handle should be closed with mapi_close_handle(). /// The command response is buffered for consumption, c.f. mapi\_fetch\_row(). /// </summary> /// <param name="mapi"></param> /// <param name="command"></param> /// <returns></returns> public static MapiHdl MapiQuery(MapiConnection mapi, string command) { return new MapiHdl(CMapiLib.mapi_query(mapi.Ptr, command)); }
/// <summary> /// Similar to mapi_query_array(), except that the response of the /// server is not analyzed, but shipped immediately to the file indicated. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <param name="args"></param> /// <param name="fs"></param> /// <returns></returns> public static MapiHdl MapiQuickQueryArray(MapiConnection mid, string command, string[] args, FileStream fs) { return new MapiHdl(CMapiLib.mapi_quick_query_array(mid.Ptr, command, args, fs.SafeFileHandle)); }
/// <summary> /// Return the current value of the trace flag. /// </summary> /// <param name="mid"></param> /// <returns></returns> public static int MapiGetTrace(MapiConnection mid) { return CMapiLib.mapi_get_trace(mid.Ptr); }
/// <summary> /// Test availability of the server. Returns zero upon success. /// </summary> /// <param name="mapi"></param> /// <returns></returns> public static MapiMsg MapiPing(MapiConnection mapi) { return new MapiMsg(CMapiLib.mapi_ping(mapi.Ptr)); }
/// <summary> /// Close the current channel (if still open) and re-establish a fresh connection. /// This will remove all global session variables. /// </summary> /// <param name="mapi"></param> /// <returns></returns> public static MapiMsg MapiReconnect(MapiConnection mapi) { return(new MapiMsg(CMapiLib.mapi_reconnect(mapi.Ptr))); }
/// <summary> /// /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string MapiGetDbName(MapiConnection mid) { return Marshal.PtrToStringAnsi(CMapiLib.mapi_get_dbname(mid.Ptr)); }
/// <summary> /// A limited number of tuples are pre-fetched after each execute(). /// If maxrows is negative, all rows will be fetched before the application is /// permitted to continue. Once the cache is filled, a number of tuples are shuffled to /// make room for new ones, but taking into account non-read elements. /// Filling the cache quicker than reading leads to an error. /// </summary> /// <param name="mid"></param> /// <param name="maxrows"></param> /// <returns></returns> public static MapiMsg MapiCacheLimit(MapiConnection mid, int maxrows) { return(new MapiMsg(CMapiLib.mapi_cache_limit(mid.Ptr, maxrows))); }
/// <summary> /// Send the Command to the database server replacing the placeholders (?) by the string arguments presented. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <param name="args"></param> /// <returns></returns> public static MapiHdl MapiQueryArray(MapiConnection mid, string command, string[] args) { return(new MapiHdl(CMapiLib.mapi_query_array(mid.Ptr, command, args))); }
/// <summary> /// Write the error message obtained from mserver to a file. /// </summary> /// <param name="mid"></param> /// <param name="fs"></param> /// <returns></returns> public static MapiMsg MapiExplain(MapiConnection mid, FileStream fs) { return(new MapiMsg(CMapiLib.mapi_explain(mid.Ptr, fs.SafeFileHandle))); }
/// <summary> /// Set the autocommit flag (default is on). /// This only has an effect when the language is SQL. /// In that case, the server commits after each statement sent to the server. /// </summary> /// <param name="mid"></param> /// <param name="autocommit"></param> /// <returns></returns> public static MapiMsg MapiSetAutocommit(MapiConnection mid, int autocommit) { return(new MapiMsg(CMapiLib.mapi_setAutocommit(mid.Ptr, autocommit))); }
/// <summary> /// Return a pointer to the last error message. /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string MapiErrorString(MapiConnection mid) { return(Marshal.PtrToStringAnsi(CMapiLib.mapi_error_str(mid.Ptr))); }
/// <summary> /// Return the last error code or 0 if there is no error. /// </summary> /// <param name="mid"></param> /// <returns></returns> public static MapiMsg MapiError(MapiConnection mid) { return(new MapiMsg(CMapiLib.mapi_error(mid.Ptr))); }
/// <summary> /// Move the query to a newly allocated query handle (which is returned). /// Possibly interact with the back-end to prepare the query for execution. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <returns></returns> public static MapiHdl MapiPrepare(MapiConnection mid, string command) { return(new MapiHdl(CMapiLib.mapi_prepare(mid.Ptr, command))); }
/// <summary> /// Send the request for processing and fetch a limited number of tuples /// (determined by the window size) to assess any erroneous situation. /// Thereafter, prepare for continual reading of tuples from the stream, /// until an error occurs. Each time a tuple arrives, the cache is shifted one. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <param name="windowSize"></param> /// <returns></returns> public static MapiHdl MapiStreamQuery(MapiConnection mid, string command, int windowSize) { return(new MapiHdl(CMapiLib.mapi_stream_query(mid.Ptr, command, windowSize))); }
/// <summary> /// Set the trace flag to monitor interaction with the server. /// </summary> /// <param name="mid"></param> /// <param name="flag"></param> /// <returns></returns> public static MapiMsg MapiTrace(MapiConnection mid, int flag) { return(new MapiMsg(CMapiLib.mapi_trace(mid.Ptr, flag))); }
/// <summary> /// Log the interaction between the client and server for offline inspection. /// Beware that the log file overwrites any previous log. It is not intended for recovery. /// </summary> /// <param name="mid"></param> /// <param name="filename"></param> /// <returns></returns> public static MapiMsg MapiTraceLog(MapiConnection mid, string filename) { return new MapiMsg(CMapiLib.mapi_trace_log(mid.Ptr, filename)); }
/// <summary> /// Return the current value of the trace flag. /// </summary> /// <param name="mid"></param> /// <returns></returns> public static int MapiGetTrace(MapiConnection mid) { return(CMapiLib.mapi_get_trace(mid.Ptr)); }
/// <summary> /// /// </summary> /// <param name="connection"></param> /// <param name="query"></param> /// <returns></returns> /// <exception cref="MonetDbException"></exception> public static MapiHdl GetQueryHandle(MapiConnection connection, string query) { var queryHandle = MapiLib.MapiQuery(connection, query); DieQueryError(connection, queryHandle); return queryHandle; }
/// <summary> /// Log the interaction between the client and server for offline inspection. /// Beware that the log file overwrites any previous log. It is not intended for recovery. /// </summary> /// <param name="mid"></param> /// <param name="filename"></param> /// <returns></returns> public static MapiMsg MapiTraceLog(MapiConnection mid, string filename) { return(new MapiMsg(CMapiLib.mapi_trace_log(mid.Ptr, filename))); }
/// <summary> /// Write the error message obtained from mserver to a file. /// </summary> /// <param name="mid"></param> /// <param name="fs"></param> /// <returns></returns> public static MapiMsg MapiExplain(MapiConnection mid, FileStream fs) { return new MapiMsg(CMapiLib.mapi_explain(mid.Ptr, fs.SafeFileHandle)); }
/// <summary> /// /// </summary> /// <param name="mid"></param> /// <param name="fnr"></param> /// <returns></returns> public static int MapiGetlen(MapiConnection mid, int fnr) { return(CMapiLib.mapi_get_len(mid.Ptr, fnr)); }
/// <summary> /// /// </summary> /// <param name="mid"></param> /// <param name="fnr"></param> /// <returns></returns> public static int MapiGetlen(MapiConnection mid, int fnr) { return CMapiLib.mapi_get_len(mid.Ptr, fnr); }
/// <summary> /// /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string MapiGetDbName(MapiConnection mid) { return(Marshal.PtrToStringAnsi(CMapiLib.mapi_get_dbname(mid.Ptr))); }
/// <summary> /// /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string MapiGetUser(MapiConnection mid) { return Marshal.PtrToStringAnsi(CMapiLib.mapi_get_user(mid.Ptr)); }
/// <summary> /// /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string MapiGetMotd(MapiConnection mid) { return(Marshal.PtrToStringAnsi(CMapiLib.mapi_get_motd(mid.Ptr))); }
/// <summary> /// Move the query to a newly allocated query handle (which is returned). /// Possibly interact with the back-end to prepare the query for execution. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <returns></returns> public static MapiHdl MapiPrepare(MapiConnection mid, string command) { return new MapiHdl(CMapiLib.mapi_prepare(mid.Ptr, command)); }
/// <summary> /// Set the autocommit flag (default is on). /// This only has an effect when the language is SQL. /// In that case, the server commits after each statement sent to the server. /// </summary> /// <param name="mid"></param> /// <param name="autocommit"></param> /// <returns></returns> public static MapiMsg MapiSetAutocommit(MapiConnection mid, int autocommit) { return new MapiMsg(CMapiLib.mapi_setAutocommit(mid.Ptr, autocommit)); }
/// <summary> /// Send the Command to the database server replacing the placeholders (?) by the string arguments presented. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <param name="args"></param> /// <returns></returns> public static MapiHdl MapiQueryArray(MapiConnection mid, string command, string[] args) { return new MapiHdl(CMapiLib.mapi_query_array(mid.Ptr, command, args)); }
/// <summary> /// Return a list of accessible database tables. /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string[] MapiTables(MapiConnection mid) { var pptr = CMapiLib.mapi_tables(mid.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> /// Close the current channel (if still open) and re-establish a fresh connection. /// This will remove all global session variables. /// </summary> /// <param name="mapi"></param> /// <returns></returns> public static MapiMsg MapiReconnect(MapiConnection mapi) { return new MapiMsg(CMapiLib.mapi_reconnect(mapi.Ptr)); }
/// <summary> /// Similar to mapi_query_array(), except that the response of the /// server is not analyzed, but shipped immediately to the file indicated. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <param name="args"></param> /// <param name="fs"></param> /// <returns></returns> public static MapiHdl MapiQuickQueryArray(MapiConnection mid, string command, string[] args, FileStream fs) { return(new MapiHdl(CMapiLib.mapi_quick_query_array(mid.Ptr, command, args, fs.SafeFileHandle))); }
/// <summary> /// Send the request for processing and fetch a limited number of tuples /// (determined by the window size) to assess any erroneous situation. /// Thereafter, prepare for continual reading of tuples from the stream, /// until an error occurs. Each time a tuple arrives, the cache is shifted one. /// </summary> /// <param name="mid"></param> /// <param name="command"></param> /// <param name="windowSize"></param> /// <returns></returns> public static MapiHdl MapiStreamQuery(MapiConnection mid, string command, int windowSize) { return new MapiHdl(CMapiLib.mapi_stream_query(mid.Ptr, command, windowSize)); }
/// <summary> /// Test availability of the server. Returns zero upon success. /// </summary> /// <param name="mapi"></param> /// <returns></returns> public static MapiMsg MapiPing(MapiConnection mapi) { return(new MapiMsg(CMapiLib.mapi_ping(mapi.Ptr))); }
/// <summary> /// Set the trace flag to monitor interaction with the server. /// </summary> /// <param name="mid"></param> /// <param name="flag"></param> /// <returns></returns> public static MapiMsg MapiTrace(MapiConnection mid, int flag) { return new MapiMsg(CMapiLib.mapi_trace(mid.Ptr, flag)); }
/// <summary> /// /// </summary> /// <param name="connection"></param> public static void CloseConnectionHandle(MapiConnection connection) { MapiLib.MapiDisconnect(connection); MapiLib.MapiDestroy(connection); }
/// <summary> /// A limited number of tuples are pre-fetched after each execute(). /// If maxrows is negative, all rows will be fetched before the application is /// permitted to continue. Once the cache is filled, a number of tuples are shuffled to /// make room for new ones, but taking into account non-read elements. /// Filling the cache quicker than reading leads to an error. /// </summary> /// <param name="mid"></param> /// <param name="maxrows"></param> /// <returns></returns> public static MapiMsg MapiCacheLimit(MapiConnection mid, int maxrows) { return new MapiMsg(CMapiLib.mapi_cache_limit(mid.Ptr, maxrows)); }
/// <summary> /// Send the Command to the database server represented by mid. /// This function returns a query handle with which the results of the /// query can be retrieved. The handle should be closed with mapi_close_handle(). /// The command response is buffered for consumption, c.f. mapi\_fetch\_row(). /// </summary> /// <param name="mapi"></param> /// <param name="command"></param> /// <returns></returns> public static MapiHdl MapiQuery(MapiConnection mapi, string command) { return(new MapiHdl(CMapiLib.mapi_query(mapi.Ptr, command))); }
/// <summary> /// Terminate the session described by mid if not already done so, and free all resources. /// The handle cannot be used anymore. /// </summary> /// <param name="mapi"></param> /// <returns></returns> public static MapiMsg MapiDestroy(MapiConnection mapi) { return new MapiMsg(CMapiLib.mapi_destroy(mapi.Ptr)); }
/// <summary> /// Return the last error code or 0 if there is no error. /// </summary> /// <param name="mid"></param> /// <returns></returns> public static MapiMsg MapiError(MapiConnection mid) { return new MapiMsg(CMapiLib.mapi_error(mid.Ptr)); }
/// <summary> /// Return a pointer to the last error message. /// </summary> /// <param name="mid"></param> /// <returns></returns> public static string MapiErrorString(MapiConnection mid) { return Marshal.PtrToStringAnsi(CMapiLib.mapi_error_str(mid.Ptr)); }
/// <summary> /// /// </summary> public void Open() { if (State == ConnectionState.Open) throw new MonetDbException("Connection already open."); _connection = MapiFactory.GetConnectionhandle(_database.ConnectionInfo); State = ConnectionState.Open; }
/// <summary> /// Terminate the session described by mid if not already done so, and free all resources. /// The handle cannot be used anymore. /// </summary> /// <param name="mapi"></param> /// <returns></returns> public static MapiMsg MapiDestroy(MapiConnection mapi) { return(new MapiMsg(CMapiLib.mapi_destroy(mapi.Ptr))); }