libgda.cs 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. using System.Data;
  12. using System.Data.Common;
  13. using System.Runtime.InteropServices;
  14. namespace System.Data.OleDb
  15. {
  16. internal enum GdaCommandOptions {
  17. IgnoreErrors = 1,
  18. StopOnErrors = 1 << 1,
  19. BadOption = 1 << 2,
  20. };
  21. internal enum GdaCommandType {
  22. Sql = 0,
  23. Xml = 1,
  24. Procedure = 2,
  25. Table = 3,
  26. Schema = 4,
  27. Invalid = 5
  28. };
  29. internal enum GdaValueType {
  30. Null = 0,
  31. Bigint = 1,
  32. Binary = 2,
  33. Boolean = 3,
  34. Date = 4,
  35. Double = 5,
  36. GeometricPoint = 6,
  37. Integer = 7,
  38. List = 8,
  39. Numeric = 9,
  40. Single = 10,
  41. Smallint = 11,
  42. String = 12,
  43. Time = 13,
  44. Timestamp = 14,
  45. Tinyint = 15,
  46. Type = 16,
  47. Unknown = 17
  48. };
  49. [StructLayout(LayoutKind.Sequential)]
  50. internal class GdaDate
  51. {
  52. public short year;
  53. public ushort month;
  54. public ushort day;
  55. }
  56. [StructLayout(LayoutKind.Sequential)]
  57. internal class GdaTime
  58. {
  59. public ushort hour;
  60. public ushort minute;
  61. public ushort second;
  62. public long timezone;
  63. }
  64. [StructLayout(LayoutKind.Sequential)]
  65. internal class GdaTimestamp
  66. {
  67. public short year;
  68. public ushort month;
  69. public ushort day;
  70. public ushort hour;
  71. public ushort minute;
  72. public ushort second;
  73. public ulong fraction;
  74. public long timezone;
  75. }
  76. [StructLayout(LayoutKind.Sequential)]
  77. internal class GdaList
  78. {
  79. public IntPtr data;
  80. public IntPtr next;
  81. public IntPtr prev;
  82. }
  83. sealed internal class libgda
  84. {
  85. private static IntPtr gdaClient = IntPtr.Zero;
  86. public static IntPtr GdaClient
  87. {
  88. get {
  89. if (gdaClient == IntPtr.Zero)
  90. gdaClient = gda_client_new ();
  91. return gdaClient;
  92. }
  93. }
  94. [DllImport("gobject-2.0",
  95. EntryPoint="g_object_unref")]
  96. public static extern void FreeObject (IntPtr obj);
  97. [DllImport("gda-2")]
  98. public static extern void gda_init (string app_id, string version, int nargs, string[] args);
  99. [DllImport("gda-2")]
  100. public static extern GdaValueType gda_value_get_vtype (IntPtr value);
  101. [DllImport("gda-2")]
  102. public static extern long gda_value_get_bigint (IntPtr value);
  103. [DllImport("gda-2")]
  104. public static extern bool gda_value_get_boolean (IntPtr value);
  105. [DllImport("gda-2")]
  106. public static extern IntPtr gda_value_get_date (IntPtr value);
  107. [DllImport("gda-2")]
  108. public static extern double gda_value_get_double (IntPtr value);
  109. [DllImport("gda-2")]
  110. public static extern int gda_value_get_integer (IntPtr value);
  111. [DllImport("gda-2")]
  112. public static extern float gda_value_get_single (IntPtr value);
  113. [DllImport("gda-2")]
  114. public static extern int gda_value_get_smallint (IntPtr value);
  115. [DllImport("gda-2")]
  116. public static extern string gda_value_get_string (IntPtr value);
  117. [DllImport("gda-2")]
  118. public static extern IntPtr gda_value_get_time (IntPtr value);
  119. [DllImport("gda-2")]
  120. public static extern IntPtr gda_value_get_timestamp (IntPtr value);
  121. [DllImport("gda-2")]
  122. public static extern byte gda_value_get_tinyint (IntPtr value);
  123. [DllImport("gda-2")]
  124. public static extern string gda_value_stringify (IntPtr value);
  125. [DllImport("gda-2")]
  126. public static extern IntPtr gda_parameter_list_new ();
  127. [DllImport("gda-2")]
  128. public static extern string gda_type_to_string (GdaValueType type);
  129. [DllImport("gda-2")]
  130. public static extern int gda_data_model_get_n_rows (IntPtr model);
  131. [DllImport("gda-2")]
  132. public static extern int gda_data_model_get_n_columns (IntPtr model);
  133. [DllImport("gda-2")]
  134. public static extern IntPtr gda_data_model_get_value_at (IntPtr model, int col, int row);
  135. [DllImport("gda-2")]
  136. public static extern string gda_data_model_get_column_title (IntPtr model, int col);
  137. [DllImport("gda-2")]
  138. public static extern IntPtr gda_data_model_describe_column (IntPtr model, int col);
  139. [DllImport("gda-2")]
  140. public static extern void gda_field_attributes_free (IntPtr fa);
  141. [DllImport("gda-2")]
  142. public static extern string gda_field_attributes_get_name (IntPtr fa);
  143. [DllImport("gda-2")]
  144. public static extern GdaValueType gda_field_attributes_get_gdatype (IntPtr fa);
  145. [DllImport("gda-2")]
  146. public static extern IntPtr gda_client_new ();
  147. [DllImport("gda-2")]
  148. public static extern IntPtr gda_client_open_connection (IntPtr client, string dsn, string username, string password);
  149. [DllImport("gda-2")]
  150. public static extern bool gda_connection_is_open (IntPtr cnc);
  151. [DllImport("gda-2")]
  152. public static extern bool gda_connection_close (IntPtr cnc);
  153. [DllImport("gda-2")]
  154. public static extern string gda_connection_get_server_version (IntPtr cnc);
  155. [DllImport("gda-2")]
  156. public static extern string gda_connection_get_database (IntPtr cnc);
  157. [DllImport("gda-2")]
  158. public static extern string gda_connection_get_dsn (IntPtr cnc);
  159. [DllImport("gda-2")]
  160. public static extern string gda_connection_get_cnc_string (IntPtr cnc);
  161. [DllImport("gda-2")]
  162. public static extern string gda_connection_get_provider (IntPtr cnc);
  163. [DllImport("gda-2")]
  164. public static extern string gda_connection_get_username (IntPtr cnc);
  165. [DllImport("gda-2")]
  166. public static extern string gda_connection_get_password (IntPtr cnc);
  167. [DllImport("gda-2")]
  168. public static extern IntPtr gda_transaction_new (string name);
  169. [DllImport("gda-2")]
  170. public static extern IntPtr gda_transaction_get_name (IntPtr xaction);
  171. [DllImport("gda-2")]
  172. public static extern IntPtr gda_transaction_set_name (IntPtr xaction, string name);
  173. [DllImport("gda-2")]
  174. public static extern bool gda_connection_begin_transaction (IntPtr cnc, IntPtr xaction);
  175. [DllImport("gda-2")]
  176. public static extern bool gda_connection_commit_transaction (IntPtr cnc, IntPtr xaction);
  177. [DllImport("gda-2")]
  178. public static extern bool gda_connection_rollback_transaction (IntPtr cnc, IntPtr xaction);
  179. [DllImport("gda-2")]
  180. public static extern IntPtr gda_connection_execute_command (IntPtr cnc, IntPtr cmd, IntPtr parameterList);
  181. [DllImport("gda-2")]
  182. public static extern int gda_connection_execute_non_query (IntPtr cnc, IntPtr command, IntPtr parameterList);
  183. [DllImport("gda-2")]
  184. public static extern IntPtr gda_connection_execute_single_command (IntPtr cnc, IntPtr command, IntPtr parameterList);
  185. [DllImport("gda-2")]
  186. public static extern IntPtr gda_command_new (string text, GdaCommandType type, GdaCommandOptions options);
  187. [DllImport("gda-2")]
  188. public static extern void gda_command_set_text (IntPtr cmd, string text);
  189. [DllImport("gda-2")]
  190. public static extern void gda_command_set_command_type (IntPtr cmd, GdaCommandType type);
  191. }
  192. }