2 * Firebird ADO.NET Data provider for .NET and Mono
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
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.
15 * Copyright (c) 2002, 2005 Carlos Guzman Alvarez
16 * All Rights Reserved.
20 using System.Collections;
21 using System.Globalization;
22 using System.Resources;
25 namespace FirebirdSql.Data.Common
27 internal sealed class IscHelper
37 #region General Static Methods
39 public static ArrayList ParseDatabaseInfo(byte[] buffer)
41 ArrayList info = new ArrayList();
47 while ((type = buffer[pos++]) != IscCodes.isc_info_end)
49 length = VaxInteger(buffer, pos, 2);
55 // Database characteristics
57 case IscCodes.isc_info_allocation:
58 // Number of database pages allocated
59 info.Add(VaxInteger(buffer, pos, length));
62 case IscCodes.isc_info_base_level:
63 /* Database version (level) number:
64 * 1 byte containing the number 1
65 * 1 byte containing the version number
67 info.Add(String.Format(CultureInfo.CurrentUICulture, "{0}.{1}", buffer[pos], buffer[pos + 1]));
70 case IscCodes.isc_info_db_id:
71 /* Database file name and site name:
72 *
\95 1 byte containing the number 2
73 *
\95 1 byte containing the length, d, of the database file name in bytes
74 *
\95 A string of d bytes, containing the database file name
75 *
\95 1 byte containing the length, l, of the site name in bytes
76 *
\95 A string of l bytes, containing the site name
78 string dbFile = Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]);
79 int sitePos = pos + 2 + buffer[pos + 1];
80 int siteLength = buffer[sitePos];
81 string siteName = Encoding.Default.GetString(buffer, sitePos + 1, siteLength);
83 sitePos += siteLength + 1;
84 siteLength = buffer[sitePos];
85 siteName += "." + Encoding.Default.GetString(buffer, sitePos + 1, siteLength);
87 info.Add(siteName + ":" + dbFile);
90 case IscCodes.isc_info_implementation:
91 /* Database implementation number:
92 *
\95 1 byte containing a 1
93 *
\95 1 byte containing the implementation number
94 *
\95 1 byte containing a
\93class
\94 number, either 1 or 12
96 info.Add(String.Format(CultureInfo.CurrentUICulture, "{0}.{1}.{2}", buffer[pos], buffer[pos + 1], buffer[pos + 2]));
99 case IscCodes.isc_info_no_reserve:
101 *
\95 0 indicates space is reserved on each database page for holding
102 * backup versions of modified records [Default]
103 *
\95 1 indicates no space is reserved for such records
105 info.Add(buffer[pos] == 1 ? true : false);
108 case IscCodes.isc_info_ods_version:
109 /* ODS major version number
110 *
\95 Databases with different major version numbers have different
111 * physical layouts; a database engine can only access databases
112 * with a particular ODS major version number
113 *
\95 Trying to attach to a database with a different ODS number
114 * results in an error
116 info.Add(VaxInteger(buffer, pos, length));
119 case IscCodes.isc_info_ods_minor_version:
120 /* On-disk structure (ODS) minor version number; an increase in a
121 * minor version number indicates a non-structural change, one that
122 * still allows the database to be accessed by database engines with
123 * the same major version number but possibly different minor
126 info.Add(VaxInteger(buffer, pos, length));
129 case IscCodes.isc_info_page_size:
130 /* Number of bytes per page of the attached database; use with
131 * isc_info_allocation to determine the size of the database
133 info.Add(VaxInteger(buffer, pos, length));
136 case IscCodes.isc_info_isc_version:
137 /* Version identification string of the database implementation:
138 *
\95 1 byte containing the number 1
139 *
\95 1 byte specifying the length, n, of the following string
140 *
\95 n bytes containing the version identification string
142 info.Add(Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]));
146 // Environmental characteristics
149 case IscCodes.isc_info_current_memory:
150 // Amount of server memory (in bytes) currently in use
151 info.Add(VaxInteger(buffer, pos, length));
154 case IscCodes.isc_info_forced_writes:
155 /* Number specifying the mode in which database writes are performed
156 * (0 for asynchronous, 1 for synchronous)
158 info.Add(buffer[pos] == 1 ? true : false);
161 case IscCodes.isc_info_max_memory:
162 /* Maximum amount of memory (in bytes) used at one time since the first
163 * process attached to the database
165 info.Add(VaxInteger(buffer, pos, length));
168 case IscCodes.isc_info_num_buffers:
169 // Number of memory buffers currently allocated
170 info.Add(VaxInteger(buffer, pos, length));
173 case IscCodes.isc_info_sweep_interval:
174 /* Number of transactions that are committed between
\93sweeps
\94 to
175 * remove database record versions that are no longer needed
177 info.Add(VaxInteger(buffer, pos, length));
181 // Performance statistics
184 case IscCodes.isc_info_fetches:
185 // Number of reads from the memory buffer cache
186 info.Add(VaxInteger(buffer, pos, length));
189 case IscCodes.isc_info_marks:
190 // Number of writes to the memory buffer cache
191 info.Add(VaxInteger(buffer, pos, length));
194 case IscCodes.isc_info_reads:
195 // Number of page reads
196 info.Add(VaxInteger(buffer, pos, length));
199 case IscCodes.isc_info_writes:
200 // Number of page writes
201 info.Add(VaxInteger(buffer, pos, length));
205 // Database operation counts
208 case IscCodes.isc_info_backout_count:
209 // Number of removals of a version of a record
210 info.Add(VaxInteger(buffer, pos, length));
213 case IscCodes.isc_info_delete_count:
214 // Number of database deletes since the database was last attached
215 info.Add(VaxInteger(buffer, pos, length));
218 case IscCodes.isc_info_expunge_count:
219 /* Number of removals of a record and all of its ancestors, for records
220 * whose deletions have been committed
222 info.Add(VaxInteger(buffer, pos, length));
225 case IscCodes.isc_info_insert_count:
226 // Number of inserts into the database since the database was last attached
227 info.Add(VaxInteger(buffer, pos, length));
230 case IscCodes.isc_info_purge_count:
231 // Number of removals of old versions of fully mature records
232 info.Add(VaxInteger(buffer, pos, length));
235 case IscCodes.isc_info_read_idx_count:
236 // Number of reads done via an index since the database was last attached
237 info.Add(VaxInteger(buffer, pos, length));
240 case IscCodes.isc_info_read_seq_count:
241 /* Number of sequential sequential table scans (row reads) done on each
242 * table since the database was last attached
244 info.Add(VaxInteger(buffer, pos, length));
247 case IscCodes.isc_info_update_count:
248 // Number of database updates since the database was last attached
249 info.Add(VaxInteger(buffer, pos, length));
256 case IscCodes.isc_info_firebird_version:
257 info.Add(Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]));
260 case IscCodes.isc_info_db_class:
261 int serverClass = VaxInteger(buffer, pos, length);
262 if (serverClass == IscCodes.isc_info_db_class_classic_access)
264 info.Add("CLASSIC SERVER");
268 info.Add("SUPER SERVER");
272 case IscCodes.isc_info_db_read_only:
273 info.Add(buffer[pos] == 1 ? true : false);
276 case IscCodes.isc_info_db_size_in_pages:
277 // Database size in pages.
278 info.Add(VaxInteger(buffer, pos, length));
281 case IscCodes.isc_info_oldest_transaction:
282 // Number of oldest transaction
283 info.Add(VaxInteger(buffer, pos, length));
286 case IscCodes.isc_info_oldest_active:
287 // Number of oldest active transaction
288 info.Add(VaxInteger(buffer, pos, length));
291 case IscCodes.isc_info_oldest_snapshot:
292 // Number of oldest snapshot transaction
293 info.Add(VaxInteger(buffer, pos, length));
296 case IscCodes.isc_info_next_transaction:
297 // Number of next transaction
298 info.Add(VaxInteger(buffer, pos, length));
301 case IscCodes.isc_info_active_transactions:
302 // Number of active transactions
303 info.Add(VaxInteger(buffer, pos, length));
313 public static int VaxInteger(byte[] buffer, int index, int length)
318 newValue = shift = 0;
321 while (--length >= 0)
323 newValue += (buffer[i++] & 0xff) << shift;