2002-08-18 Rodrigo Moya <rodrigo@ximian.com>
[mono.git] / mcs / class / System.Data / System.Data.OleDb / libgda.cs
1 //
2 // System.Data.OleDb.libgda
3 //
4 // Authors:
5 //   Rodrigo Moya (rodrigo@ximian.com)
6 //   Tim Coleman (tim@timcoleman.com)
7 //
8 // Copyright (C) Rodrigo Moya, 2002
9 // Copyright (C) Tim Coleman, 2002
10 //
11
12 using System.Data;
13 using System.Data.Common;
14 using System.Runtime.InteropServices;
15
16 namespace System.Data.OleDb
17 {
18         internal enum GdaCommandOptions {
19                 IgnoreErrors = 1,
20                 StopOnErrors = 1 << 1,
21                 BadOption = 1 << 2,
22         };
23
24         internal enum GdaCommandType {
25                 Sql = 0,
26                 Xml = 1,
27                 Procedure = 2,
28                 Table = 3,
29                 Schema = 4,
30                 Invalid = 5
31         };
32
33         internal enum GdaValueType {
34                 Null = 0,
35                 Bigint = 1,
36                 Binary = 2,
37                 Boolean = 3,
38                 Date = 4,
39                 Double = 5,
40                 GeometricPoint = 6,
41                 Integer = 7,
42                 List = 8,
43                 Numeric = 9,
44                 Single = 10,
45                 Smallint = 11,
46                 String = 12,
47                 Time = 13,
48                 Timestamp = 14,
49                 Tinyint = 15,
50                 Type = 16,
51                 Unknown = 17
52         };
53
54         [StructLayout(LayoutKind.Sequential)]
55         internal class GdaDate
56         {
57                 public short year;
58                 public ushort month;
59                 public ushort day;
60         }
61
62         [StructLayout(LayoutKind.Sequential)]
63         internal class GdaTime
64         {
65                 public ushort hour;
66                 public ushort minute;
67                 public ushort second;
68                 public long timezone;
69         }
70         
71         [StructLayout(LayoutKind.Sequential)]
72         internal class GdaTimestamp
73         {
74                 public short year;
75                 public ushort month;
76                 public ushort day;
77                 public ushort hour;
78                 public ushort minute;
79                 public ushort second;
80                 public ulong fraction;
81                 public long timezone;
82         }
83         
84         [StructLayout(LayoutKind.Sequential)]
85         internal class GdaList
86         {
87                 public IntPtr data;
88                 public IntPtr next;
89                 public IntPtr prev;
90         }
91         
92         sealed internal class libgda
93         {
94                 private static IntPtr gdaClient = IntPtr.Zero;
95
96                 public static IntPtr GdaClient
97                 {
98                         get {
99                                 if (gdaClient == IntPtr.Zero)
100                                         gdaClient = gda_client_new ();
101
102                                 return gdaClient;
103                         }
104                 }
105
106                 [DllImport("gobject-2.0",
107                            EntryPoint="g_object_unref")]
108                 public static extern void FreeObject (IntPtr obj);
109
110                 [DllImport("gda-2")]
111                 public static extern void gda_init (string app_id, string version, int nargs, string[] args);
112
113                 [DllImport("gda-2")]
114                 public static extern GdaValueType gda_value_get_vtype (IntPtr value);
115
116                 [DllImport("gda-2")]
117                 public static extern long gda_value_get_bigint (IntPtr value);
118                 
119                 [DllImport("gda-2")]
120                 public static extern bool gda_value_get_boolean (IntPtr value);
121
122                 [DllImport("gda-2")]
123                 public static extern IntPtr gda_value_get_date (IntPtr value);
124                 
125                 [DllImport("gda-2")]
126                 public static extern double gda_value_get_double (IntPtr value);
127
128                 [DllImport("gda-2")]
129                 public static extern int gda_value_get_integer (IntPtr value);
130                 
131                 [DllImport("gda-2")]
132                 public static extern float gda_value_get_single (IntPtr value);
133                 
134                 [DllImport("gda-2")]
135                 public static extern int gda_value_get_smallint (IntPtr value);
136
137                 [DllImport("gda-2")]
138                 public static extern string gda_value_get_string (IntPtr value);
139
140                 [DllImport("gda-2")]
141                 public static extern IntPtr gda_value_get_time (IntPtr value);
142                 
143                 [DllImport("gda-2")]
144                 public static extern IntPtr gda_value_get_timestamp (IntPtr value);
145                 
146                 [DllImport("gda-2")]
147                 public static extern byte gda_value_get_tinyint (IntPtr value);
148
149                 [DllImport("gda-2")]
150                 public static extern string gda_value_stringify (IntPtr value);
151                 
152                 [DllImport("gda-2")]
153                 public static extern IntPtr gda_parameter_list_new ();
154
155                 [DllImport("gda-2")]
156                 public static extern string gda_type_to_string (GdaValueType type);
157                 
158                 [DllImport("gda-2")]
159                 public static extern int gda_data_model_get_n_rows (IntPtr model);
160
161                 [DllImport("gda-2")]
162                 public static extern int gda_data_model_get_n_columns (IntPtr model);
163
164                 [DllImport("gda-2")]
165                 public static extern IntPtr gda_data_model_get_value_at (IntPtr model, int col, int row);
166
167                 [DllImport("gda-2")]
168                 public static extern string gda_data_model_get_column_title (IntPtr model, int col);
169
170                 [DllImport("gda-2")]
171                 public static extern IntPtr gda_data_model_describe_column (IntPtr model, int col);
172
173                 [DllImport("gda-2")]
174                 public static extern void gda_field_attributes_free (IntPtr fa);
175
176                 [DllImport("gda-2")]
177                 public static extern string gda_field_attributes_get_name (IntPtr fa);
178
179                 [DllImport("gda-2")]
180                 public static extern GdaValueType gda_field_attributes_get_gdatype (IntPtr fa);
181                 
182                 [DllImport("gda-2")]
183                 public static extern IntPtr gda_client_new ();
184
185                 [DllImport("gda-2")]
186                 public static extern IntPtr gda_client_open_connection (IntPtr client, string dsn, string username, string password);
187
188                 [DllImport("gda-2")]
189                 public static extern bool gda_connection_is_open (IntPtr cnc);
190                 
191                 [DllImport("gda-2")]
192                 public static extern bool gda_connection_close (IntPtr cnc);
193
194                 [DllImport("gda-2")]
195                 public static extern string gda_connection_get_server_version (IntPtr cnc);
196                 
197                 [DllImport("gda-2")]
198                 public static extern string gda_connection_get_database (IntPtr cnc);
199
200                 [DllImport("gda-2")]
201                 public static extern string gda_connection_get_dsn (IntPtr cnc);
202
203                 [DllImport("gda-2")]
204                 public static extern string gda_connection_get_cnc_string (IntPtr cnc);
205
206                 [DllImport("gda-2")]
207                 public static extern string gda_connection_get_provider (IntPtr cnc);
208
209                 [DllImport("gda-2")]
210                 public static extern string gda_connection_get_username (IntPtr cnc);
211
212                 [DllImport("gda-2")]
213                 public static extern string gda_connection_get_password (IntPtr cnc);
214
215                 [DllImport("gda-2")]
216                 public static extern bool gda_connection_change_database (IntPtr cnc, string name);
217                 
218                 [DllImport("gda-2")]
219                 public static extern IntPtr gda_transaction_new (string name);
220
221                 [DllImport("gda-2")]
222                 public static extern IntPtr gda_transaction_get_name (IntPtr xaction);
223
224                 [DllImport("gda-2")]
225                 public static extern IntPtr gda_transaction_set_name (IntPtr xaction, string name);
226         
227                 [DllImport("gda-2")]
228                 public static extern bool gda_connection_begin_transaction (IntPtr cnc, IntPtr xaction);
229
230                 [DllImport("gda-2")]
231                 public static extern bool gda_connection_commit_transaction (IntPtr cnc, IntPtr xaction);
232
233                 [DllImport("gda-2")]
234                 public static extern bool gda_connection_rollback_transaction (IntPtr cnc, IntPtr xaction);
235
236                 [DllImport("gda-2")]
237                 public static extern IntPtr gda_connection_execute_command (IntPtr cnc, IntPtr cmd, IntPtr parameterList);
238                 
239                 [DllImport("gda-2")]
240                 public static extern int gda_connection_execute_non_query (IntPtr cnc, IntPtr command, IntPtr parameterList);
241
242                 [DllImport("gda-2")]
243                 public static extern IntPtr gda_connection_execute_single_command (IntPtr cnc, IntPtr command, IntPtr parameterList);
244
245                 [DllImport("gda-2")]
246                 public static extern IntPtr gda_connection_get_errors (IntPtr cnc);
247
248                 [DllImport("gda-2")]
249                 public static extern IntPtr gda_command_new (string text, GdaCommandType type, GdaCommandOptions options);
250
251                 [DllImport("gda-2")]
252                 public static extern void gda_command_set_text (IntPtr cmd, string text);
253
254                 [DllImport("gda-2")]
255                 public static extern void gda_command_set_command_type (IntPtr cmd, GdaCommandType type);
256
257                 [DllImport("gda-2")]
258                 public static extern string gda_error_get_description (IntPtr error);
259
260                 [DllImport("gda-2")]
261                 public static extern long gda_error_get_number (IntPtr error);
262
263                 [DllImport("gda-2")]
264                 public static extern string gda_error_get_source (IntPtr error);
265                 
266                 [DllImport("gda-2")]
267                 public static extern string gda_error_get_sqlstate (IntPtr error);
268                 
269         }
270 }