libgda.cs 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. //
  2. // System.Data.OleDb.libgda
  3. //
  4. // Authors:
  5. // Rodrigo Moya ([email protected])
  6. // Tim Coleman ([email protected])
  7. //
  8. // Copyright (C) Rodrigo Moya, 2002
  9. // Copyright (C) Tim Coleman, 2002
  10. //
  11. //
  12. // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
  13. //
  14. // Permission is hereby granted, free of charge, to any person obtaining
  15. // a copy of this software and associated documentation files (the
  16. // "Software"), to deal in the Software without restriction, including
  17. // without limitation the rights to use, copy, modify, merge, publish,
  18. // distribute, sublicense, and/or sell copies of the Software, and to
  19. // permit persons to whom the Software is furnished to do so, subject to
  20. // the following conditions:
  21. //
  22. // The above copyright notice and this permission notice shall be
  23. // included in all copies or substantial portions of the Software.
  24. //
  25. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  26. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  27. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  28. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  29. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  30. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  31. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  32. //
  33. using System.Data;
  34. using System.Data.Common;
  35. using System.Runtime.InteropServices;
  36. namespace System.Data.OleDb
  37. {
  38. internal enum GdaConnectionOptions {
  39. ReadOnly = 1 << 0
  40. };
  41. internal enum GdaCommandOptions {
  42. IgnoreErrors = 1,
  43. StopOnErrors = 1 << 1,
  44. BadOption = 1 << 2,
  45. };
  46. internal enum GdaCommandType {
  47. Sql = 0,
  48. Xml = 1,
  49. Procedure = 2,
  50. Table = 3,
  51. Schema = 4,
  52. Invalid = 5
  53. };
  54. internal enum GdaTransactionIsolation {
  55. Unknown,
  56. ReadCommitted,
  57. ReadUncommitted,
  58. RepeatableRead,
  59. Serializable
  60. };
  61. internal enum GdaValueType {
  62. Null = 0,
  63. Bigint = 1,
  64. Binary = 2,
  65. Boolean = 3,
  66. Date = 4,
  67. Double = 5,
  68. GeometricPoint = 6,
  69. Integer = 7,
  70. List = 8,
  71. Numeric = 9,
  72. Single = 10,
  73. Smallint = 11,
  74. String = 12,
  75. Time = 13,
  76. Timestamp = 14,
  77. Tinyint = 15,
  78. Type = 16,
  79. Unknown = 17
  80. };
  81. [StructLayout(LayoutKind.Sequential)]
  82. internal class GdaDate
  83. {
  84. public short year;
  85. public ushort month;
  86. public ushort day;
  87. }
  88. [StructLayout(LayoutKind.Sequential)]
  89. internal class GdaTime
  90. {
  91. public ushort hour;
  92. public ushort minute;
  93. public ushort second;
  94. public long timezone;
  95. }
  96. [StructLayout(LayoutKind.Sequential)]
  97. internal class GdaTimestamp
  98. {
  99. public short year;
  100. public ushort month;
  101. public ushort day;
  102. public ushort hour;
  103. public ushort minute;
  104. public ushort second;
  105. public ulong fraction;
  106. public long timezone;
  107. }
  108. [StructLayout(LayoutKind.Sequential)]
  109. internal class GdaList
  110. {
  111. public IntPtr data;
  112. public IntPtr next;
  113. public IntPtr prev;
  114. }
  115. sealed internal class libgda
  116. {
  117. private static IntPtr gdaClient = IntPtr.Zero;
  118. public static IntPtr GdaClient
  119. {
  120. get {
  121. if (gdaClient == IntPtr.Zero)
  122. gdaClient = gda_client_new ();
  123. return gdaClient;
  124. }
  125. }
  126. [DllImport("gobject-2.0",
  127. EntryPoint="g_object_unref")]
  128. public static extern void FreeObject (IntPtr obj);
  129. [DllImport("gda-2")]
  130. public static extern void gda_init (string app_id, string version, int nargs, string[] args);
  131. [DllImport("gda-2")]
  132. public static extern GdaValueType gda_value_get_type (IntPtr value);
  133. [DllImport("gda-2")]
  134. public static extern long gda_value_get_bigint (IntPtr value);
  135. [DllImport("gda-2")]
  136. public static extern bool gda_value_get_boolean (IntPtr value);
  137. [DllImport("gda-2")]
  138. public static extern IntPtr gda_value_get_date (IntPtr value);
  139. [DllImport("gda-2")]
  140. public static extern double gda_value_get_double (IntPtr value);
  141. [DllImport("gda-2")]
  142. public static extern int gda_value_get_integer (IntPtr value);
  143. [DllImport("gda-2")]
  144. public static extern float gda_value_get_single (IntPtr value);
  145. [DllImport("gda-2")]
  146. public static extern int gda_value_get_smallint (IntPtr value);
  147. [DllImport("gda-2")]
  148. public static extern string gda_value_get_string (IntPtr value);
  149. [DllImport("gda-2")]
  150. public static extern IntPtr gda_value_get_time (IntPtr value);
  151. [DllImport("gda-2")]
  152. public static extern IntPtr gda_value_get_timestamp (IntPtr value);
  153. [DllImport("gda-2")]
  154. public static extern byte gda_value_get_tinyint (IntPtr value);
  155. [DllImport("gda-2")]
  156. public static extern bool gda_value_is_null (IntPtr value);
  157. [DllImport("gda-2")]
  158. public static extern string gda_value_stringify (IntPtr value);
  159. [DllImport("gda-2")]
  160. public static extern IntPtr gda_parameter_list_new ();
  161. [DllImport("gda-2")]
  162. public static extern string gda_type_to_string (GdaValueType type);
  163. [DllImport("gda-2")]
  164. public static extern int gda_data_model_get_n_rows (IntPtr model);
  165. [DllImport("gda-2")]
  166. public static extern int gda_data_model_get_n_columns (IntPtr model);
  167. [DllImport("gda-2")]
  168. public static extern IntPtr gda_data_model_get_value_at (IntPtr model, int col, int row);
  169. [DllImport("gda-2")]
  170. public static extern string gda_data_model_get_column_title (IntPtr model, int col);
  171. [DllImport("gda-2")]
  172. public static extern IntPtr gda_data_model_describe_column (IntPtr model, int col);
  173. [DllImport("gda-2")]
  174. public static extern int gda_data_model_get_column_position (IntPtr model, string name);
  175. [DllImport("gda-2")]
  176. public static extern void gda_field_attributes_free (IntPtr fa);
  177. [DllImport("gda-2")]
  178. public static extern string gda_field_attributes_get_name (IntPtr fa);
  179. [DllImport("gda-2")]
  180. public static extern GdaValueType gda_field_attributes_get_gdatype (IntPtr fa);
  181. [DllImport("gda-2")]
  182. public static extern long gda_field_attributes_get_defined_size (IntPtr fa);
  183. [DllImport("gda-2")]
  184. public static extern long gda_field_attributes_get_scale (IntPtr fa);
  185. [DllImport("gda-2")]
  186. public static extern bool gda_field_attributes_get_allow_null (IntPtr fa);
  187. [DllImport("gda-2")]
  188. public static extern bool gda_field_attributes_get_primary_key (IntPtr fa);
  189. [DllImport("gda-2")]
  190. public static extern bool gda_field_attributes_get_unique_key (IntPtr fa);
  191. [DllImport("gda-2")]
  192. public static extern IntPtr gda_client_new ();
  193. [DllImport("gda-2")]
  194. public static extern IntPtr gda_client_open_connection (IntPtr client, string dsn,
  195. string username, string password,
  196. GdaConnectionOptions options);
  197. [DllImport("gda-2")]
  198. public static extern IntPtr gda_client_open_connection_from_string (IntPtr client,
  199. string provider,
  200. string cnc_string,
  201. GdaConnectionOptions options);
  202. [DllImport("gda-2")]
  203. public static extern bool gda_connection_is_open (IntPtr cnc);
  204. [DllImport("gda-2")]
  205. public static extern bool gda_connection_close (IntPtr cnc);
  206. [DllImport("gda-2")]
  207. public static extern string gda_connection_get_server_version (IntPtr cnc);
  208. [DllImport("gda-2")]
  209. public static extern string gda_connection_get_database (IntPtr cnc);
  210. [DllImport("gda-2")]
  211. public static extern string gda_connection_get_dsn (IntPtr cnc);
  212. [DllImport("gda-2")]
  213. public static extern string gda_connection_get_cnc_string (IntPtr cnc);
  214. [DllImport("gda-2")]
  215. public static extern string gda_connection_get_provider (IntPtr cnc);
  216. [DllImport("gda-2")]
  217. public static extern string gda_connection_get_username (IntPtr cnc);
  218. [DllImport("gda-2")]
  219. public static extern string gda_connection_get_password (IntPtr cnc);
  220. [DllImport("gda-2")]
  221. public static extern bool gda_connection_change_database (IntPtr cnc, string name);
  222. [DllImport("gda-2")]
  223. public static extern IntPtr gda_transaction_new (string name);
  224. [DllImport("gda-2")]
  225. public static extern IntPtr gda_transaction_get_name (IntPtr xaction);
  226. [DllImport("gda-2")]
  227. public static extern IntPtr gda_transaction_set_name (IntPtr xaction, string name);
  228. [DllImport("gda-2")]
  229. public static extern GdaTransactionIsolation gda_transaction_get_isolation_level (IntPtr xaction);
  230. [DllImport("gda-2")]
  231. public static extern void gda_transaction_set_isolation_level (IntPtr xaction,
  232. GdaTransactionIsolation level);
  233. [DllImport("gda-2")]
  234. public static extern bool gda_connection_begin_transaction (IntPtr cnc, IntPtr xaction);
  235. [DllImport("gda-2")]
  236. public static extern bool gda_connection_commit_transaction (IntPtr cnc, IntPtr xaction);
  237. [DllImport("gda-2")]
  238. public static extern bool gda_connection_rollback_transaction (IntPtr cnc, IntPtr xaction);
  239. [DllImport("gda-2")]
  240. public static extern IntPtr gda_connection_execute_command (IntPtr cnc, IntPtr cmd, IntPtr parameterList);
  241. [DllImport("gda-2")]
  242. public static extern int gda_connection_execute_non_query (IntPtr cnc, IntPtr command, IntPtr parameterList);
  243. [DllImport("gda-2")]
  244. public static extern IntPtr gda_connection_execute_single_command (IntPtr cnc, IntPtr command, IntPtr parameterList);
  245. [DllImport("gda-2")]
  246. public static extern IntPtr gda_connection_get_errors (IntPtr cnc);
  247. [DllImport("gda-2")]
  248. public static extern IntPtr gda_command_new (string text, GdaCommandType type, GdaCommandOptions options);
  249. [DllImport("gda-2")]
  250. public static extern void gda_command_set_text (IntPtr cmd, string text);
  251. [DllImport("gda-2")]
  252. public static extern void gda_command_set_command_type (IntPtr cmd, GdaCommandType type);
  253. [DllImport("gda-2")]
  254. public static extern string gda_error_get_description (IntPtr error);
  255. [DllImport("gda-2")]
  256. public static extern long gda_error_get_number (IntPtr error);
  257. [DllImport("gda-2")]
  258. public static extern string gda_error_get_source (IntPtr error);
  259. [DllImport("gda-2")]
  260. public static extern string gda_error_get_sqlstate (IntPtr error);
  261. }
  262. }