2009-05-13 Atsushi Enomoto <atsushi@ximian.com>
[mono.git] / mcs / class / FirebirdSql.Data.Firebird / FirebirdSql.Data.Embedded / FesConnection.cs
1 /*
2  *      Firebird ADO.NET Data provider for .NET and Mono 
3  * 
4  *         The contents of this file are subject to the Initial 
5  *         Developer's Public License Version 1.0 (the "License"); 
6  *         you may not use this file except in compliance with the 
7  *         License. You may obtain a copy of the License at 
8  *         http://www.firebirdsql.org/index.php?op=doc&id=idpl
9  *
10  *         Software distributed under the License is distributed on 
11  *         an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either 
12  *         express or implied. See the License for the specific 
13  *         language governing rights and limitations under the License.
14  * 
15  *      Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16  *      All Rights Reserved.
17  */
18
19 using System;
20 using System.Runtime.InteropServices;
21
22 using FirebirdSql.Data.Common;
23
24 namespace FirebirdSql.Data.Embedded
25 {
26         internal sealed class FesConnection
27         {
28                 #region Constructors
29
30                 private FesConnection()
31                 {
32                 }
33
34                 #endregion
35
36                 #region Static Methods
37
38                 public static int[] GetNewStatusVector()
39                 {
40                         return new int[IscCodes.ISC_STATUS_LENGTH];
41                 }
42
43                 public static IscException ParseStatusVector(int[] statusVector)
44                 {
45                         IscException exception = null;
46                         bool eof = false;
47
48                         for (int i = 0; i < statusVector.Length; )
49                         {
50                                 int arg = statusVector[i++];
51
52                                 switch (arg)
53                                 {
54                                         case IscCodes.isc_arg_gds:
55                                                 int er = statusVector[i++];
56                                                 if (er != 0)
57                                                 {
58                                                         if (exception == null)
59                                                         {
60                                                                 exception = new IscException();
61                                                         }
62                                                         exception.Errors.Add(arg, er);
63                                                 }
64                                                 break;
65
66                                         case IscCodes.isc_arg_end:
67                                                 if (exception != null && exception.Errors.Count != 0)
68                                                 {
69                                                         exception.BuildExceptionMessage();
70                                                 }
71                                                 eof = true;
72                                                 break;
73
74                                         case IscCodes.isc_arg_interpreted:
75                                         case IscCodes.isc_arg_string:
76                                                 {
77                                                         IntPtr ptr = new IntPtr(statusVector[i++]);
78                                                         string arg_value = Marshal.PtrToStringAnsi(ptr);
79                                                         exception.Errors.Add(arg, arg_value);
80                                                 }
81                                                 break;
82
83                                         case IscCodes.isc_arg_cstring:
84                                                 {
85                                                         i++;
86
87                                                         IntPtr ptr = new IntPtr(statusVector[i++]);
88                                                         string arg_value = Marshal.PtrToStringAnsi(ptr);
89                                                         exception.Errors.Add(arg, arg_value);
90                                                 }
91                                                 break;
92
93                                         case IscCodes.isc_arg_win32:
94                                         case IscCodes.isc_arg_number:
95                                                 exception.Errors.Add(arg, statusVector[i++]);
96                                                 break;
97
98                                         default:
99                                                 {
100                                                         int e = statusVector[i++];
101                                                         if (e != 0)
102                                                         {
103                                                                 if (exception == null)
104                                                                 {
105                                                                         exception = new IscException();
106                                                                 }
107                                                                 exception.Errors.Add(arg, e);
108                                                         }
109                                                 }
110                                                 break;
111                                 }
112
113                                 if (eof)
114                                 {
115                                         break;
116                                 }
117                         }
118
119                         return exception;
120                 }
121
122                 #endregion
123         }
124 }