2 * Firebird ADO.NET Data provider for .NET and Mono
\r
4 * The contents of this file are subject to the Initial
\r
5 * Developer's Public License Version 1.0 (the "License");
\r
6 * you may not use this file except in compliance with the
\r
7 * License. You may obtain a copy of the License at
\r
8 * http://www.firebirdsql.org/index.php?op=doc&id=idpl
\r
10 * Software distributed under the License is distributed on
\r
11 * an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
\r
12 * express or implied. See the License for the specific
\r
13 * language governing rights and limitations under the License.
\r
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
\r
16 * All Rights Reserved.
\r
20 using System.Collections;
\r
21 using System.Globalization;
\r
22 using System.Resources;
\r
25 namespace FirebirdSql.Data.Common
\r
27 internal sealed class IscHelper
\r
29 #region Constructors
\r
37 #region General Static Methods
\r
39 public static ArrayList ParseDatabaseInfo(byte[] buffer)
\r
41 ArrayList info = new ArrayList();
\r
47 while ((type = buffer[pos++]) != IscCodes.isc_info_end)
\r
49 length = VaxInteger(buffer, pos, 2);
\r
55 // Database characteristics
\r
57 case IscCodes.isc_info_allocation:
\r
58 // Number of database pages allocated
\r
59 info.Add(VaxInteger(buffer, pos, length));
\r
62 case IscCodes.isc_info_base_level:
\r
63 /* Database version (level) number:
\r
64 * 1 byte containing the number 1
\r
65 * 1 byte containing the version number
\r
67 info.Add(String.Format(CultureInfo.CurrentCulture, "{0}.{1}", buffer[pos], buffer[pos + 1]));
\r
70 case IscCodes.isc_info_db_id:
\r
71 /* Database file name and site name:
\r
72 *
\95 1 byte containing the number 2
\r
73 *
\95 1 byte containing the length, d, of the database file name in bytes
\r
74 *
\95 A string of d bytes, containing the database file name
\r
75 *
\95 1 byte containing the length, l, of the site name in bytes
\r
76 *
\95 A string of l bytes, containing the site name
\r
78 string dbFile = Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]);
\r
79 int sitePos = pos + 2 + buffer[pos + 1];
\r
80 int siteLength = buffer[sitePos];
\r
81 string siteName = Encoding.Default.GetString(buffer, sitePos + 1, siteLength);
\r
83 sitePos += siteLength + 1;
\r
84 siteLength = buffer[sitePos];
\r
85 siteName += "." + Encoding.Default.GetString(buffer, sitePos + 1, siteLength);
\r
87 info.Add(siteName + ":" + dbFile);
\r
90 case IscCodes.isc_info_implementation:
\r
91 /* Database implementation number:
\r
92 *
\95 1 byte containing a 1
\r
93 *
\95 1 byte containing the implementation number
\r
94 *
\95 1 byte containing a
\93class
\94 number, either 1 or 12
\r
96 info.Add(String.Format(CultureInfo.CurrentCulture, "{0}.{1}.{2}", buffer[pos], buffer[pos + 1], buffer[pos + 2]));
\r
99 case IscCodes.isc_info_no_reserve:
\r
101 *
\95 0 indicates space is reserved on each database page for holding
\r
102 * backup versions of modified records [Default]
\r
103 *
\95 1 indicates no space is reserved for such records
\r
105 info.Add(buffer[pos] == 1 ? true : false);
\r
108 case IscCodes.isc_info_ods_version:
\r
109 /* ODS major version number
\r
110 *
\95 Databases with different major version numbers have different
\r
111 * physical layouts; a database engine can only access databases
\r
112 * with a particular ODS major version number
\r
113 *
\95 Trying to attach to a database with a different ODS number
\r
114 * results in an error
\r
116 info.Add(VaxInteger(buffer, pos, length));
\r
119 case IscCodes.isc_info_ods_minor_version:
\r
120 /* On-disk structure (ODS) minor version number; an increase in a
\r
121 * minor version number indicates a non-structural change, one that
\r
122 * still allows the database to be accessed by database engines with
\r
123 * the same major version number but possibly different minor
\r
126 info.Add(VaxInteger(buffer, pos, length));
\r
129 case IscCodes.isc_info_page_size:
\r
130 /* Number of bytes per page of the attached database; use with
\r
131 * isc_info_allocation to determine the size of the database
\r
133 info.Add(VaxInteger(buffer, pos, length));
\r
136 case IscCodes.isc_info_isc_version:
\r
137 /* Version identification string of the database implementation:
\r
138 *
\95 1 byte containing the number 1
\r
139 *
\95 1 byte specifying the length, n, of the following string
\r
140 *
\95 n bytes containing the version identification string
\r
142 info.Add(Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]));
\r
146 // Environmental characteristics
\r
149 case IscCodes.isc_info_current_memory:
\r
150 // Amount of server memory (in bytes) currently in use
\r
151 info.Add(VaxInteger(buffer, pos, length));
\r
154 case IscCodes.isc_info_forced_writes:
\r
155 /* Number specifying the mode in which database writes are performed
\r
156 * (0 for asynchronous, 1 for synchronous)
\r
158 info.Add(buffer[pos] == 1 ? true : false);
\r
161 case IscCodes.isc_info_max_memory:
\r
162 /* Maximum amount of memory (in bytes) used at one time since the first
\r
163 * process attached to the database
\r
165 info.Add(VaxInteger(buffer, pos, length));
\r
168 case IscCodes.isc_info_num_buffers:
\r
169 // Number of memory buffers currently allocated
\r
170 info.Add(VaxInteger(buffer, pos, length));
\r
173 case IscCodes.isc_info_sweep_interval:
\r
174 /* Number of transactions that are committed between
\93sweeps
\94 to
\r
175 * remove database record versions that are no longer needed
\r
177 info.Add(VaxInteger(buffer, pos, length));
\r
181 // Performance statistics
\r
184 case IscCodes.isc_info_fetches:
\r
185 // Number of reads from the memory buffer cache
\r
186 info.Add(VaxInteger(buffer, pos, length));
\r
189 case IscCodes.isc_info_marks:
\r
190 // Number of writes to the memory buffer cache
\r
191 info.Add(VaxInteger(buffer, pos, length));
\r
194 case IscCodes.isc_info_reads:
\r
195 // Number of page reads
\r
196 info.Add(VaxInteger(buffer, pos, length));
\r
199 case IscCodes.isc_info_writes:
\r
200 // Number of page writes
\r
201 info.Add(VaxInteger(buffer, pos, length));
\r
205 // Database operation counts
\r
207 case IscCodes.isc_info_backout_count:
\r
208 // Number of removals of a version of a record
\r
209 info.Add(VaxInteger(buffer, pos, length));
\r
212 case IscCodes.isc_info_delete_count:
\r
213 // Number of database deletes since the database was last attached
\r
214 info.Add(VaxInteger(buffer, pos, length));
\r
217 case IscCodes.isc_info_expunge_count:
\r
218 /* Number of removals of a record and all of its ancestors, for records
\r
219 * whose deletions have been committed
\r
221 info.Add(VaxInteger(buffer, pos, length));
\r
224 case IscCodes.isc_info_insert_count:
\r
225 // Number of inserts into the database since the database was last attached
\r
226 info.Add(VaxInteger(buffer, pos, length));
\r
229 case IscCodes.isc_info_purge_count:
\r
230 // Number of removals of old versions of fully mature records
\r
231 info.Add(VaxInteger(buffer, pos, length));
\r
234 case IscCodes.isc_info_read_idx_count:
\r
235 // Number of reads done via an index since the database was last attached
\r
236 info.Add(VaxInteger(buffer, pos, length));
\r
239 case IscCodes.isc_info_read_seq_count:
\r
240 /* Number of sequential sequential table scans (row reads) done on each
\r
241 * table since the database was last attached
\r
243 info.Add(VaxInteger(buffer, pos, length));
\r
246 case IscCodes.isc_info_update_count:
\r
247 // Number of database updates since the database was last attached
\r
248 info.Add(VaxInteger(buffer, pos, length));
\r
254 case IscCodes.isc_info_firebird_version:
\r
255 info.Add(Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]));
\r
258 case IscCodes.isc_info_db_class:
\r
259 int serverClass = VaxInteger(buffer, pos, length);
\r
260 if (serverClass == IscCodes.isc_info_db_class_classic_access)
\r
262 info.Add("CLASSIC SERVER");
\r
266 info.Add("SUPER SERVER");
\r
270 case IscCodes.isc_info_db_read_only:
\r
271 info.Add(buffer[pos] == 1 ? true : false);
\r
274 case IscCodes.isc_info_db_size_in_pages:
\r
275 // Database size in pages.
\r
276 info.Add(VaxInteger(buffer, pos, length));
\r
279 case IscCodes.isc_info_oldest_transaction:
\r
280 // Number of oldest transaction
\r
281 info.Add(VaxInteger(buffer, pos, length));
\r
284 case IscCodes.isc_info_oldest_active:
\r
285 // Number of oldest active transaction
\r
286 info.Add(VaxInteger(buffer, pos, length));
\r
289 case IscCodes.isc_info_oldest_snapshot:
\r
290 // Number of oldest snapshot transaction
\r
291 info.Add(VaxInteger(buffer, pos, length));
\r
294 case IscCodes.isc_info_next_transaction:
\r
295 // Number of next transaction
\r
296 info.Add(VaxInteger(buffer, pos, length));
\r
299 case IscCodes.isc_info_active_transactions:
\r
300 // Number of active transactions
\r
301 info.Add(VaxInteger(buffer, pos, length));
\r
304 case IscCodes.isc_info_user_names:
\r
305 // Active user name
\r
306 info.Add(Encoding.Default.GetString(buffer, pos + 1, buffer[pos]));
\r
316 public static int VaxInteger(byte[] buffer, int index, int length)
\r
321 newValue = shift = 0;
\r
324 while (--length >= 0)
\r
326 newValue += (buffer[i++] & 0xff) << shift;
\r