1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335
|
/*
* Firebird ADO.NET Data provider for .NET and Mono
*
* The contents of this file are subject to the Initial
* Developer's Public License Version 1.0 (the "License");
* you may not use this file except in compliance with the
* License. You may obtain a copy of the License at
* http://www.firebirdsql.org/index.php?op=doc&id=idpl
*
* Software distributed under the License is distributed on
* an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the License for the specific
* language governing rights and limitations under the License.
*
* Copyright (c) 2002, 2005 Carlos Guzman Alvarez
* All Rights Reserved.
*/
using System;
using System.Collections;
using System.Globalization;
using System.Resources;
using System.Text;
namespace FirebirdSql.Data.Common
{
internal sealed class IscHelper
{
#region Constructors
private IscHelper()
{
}
#endregion
#region General Static Methods
public static ArrayList ParseDatabaseInfo(byte[] buffer)
{
ArrayList info = new ArrayList();
int pos = 0;
int length = 0;
int type = 0;
while ((type = buffer[pos++]) != IscCodes.isc_info_end)
{
length = VaxInteger(buffer, pos, 2);
pos += 2;
switch (type)
{
//
// Database characteristics
//
case IscCodes.isc_info_allocation:
// Number of database pages allocated
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_base_level:
/* Database version (level) number:
* 1 byte containing the number 1
* 1 byte containing the version number
*/
info.Add(String.Format(CultureInfo.CurrentCulture, "{0}.{1}", buffer[pos], buffer[pos + 1]));
break;
case IscCodes.isc_info_db_id:
/* Database file name and site name:
* 1 byte containing the number 2
* 1 byte containing the length, d, of the database file name in bytes
* A string of d bytes, containing the database file name
* 1 byte containing the length, l, of the site name in bytes
* A string of l bytes, containing the site name
*/
string dbFile = Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]);
int sitePos = pos + 2 + buffer[pos + 1];
int siteLength = buffer[sitePos];
string siteName = Encoding.Default.GetString(buffer, sitePos + 1, siteLength);
sitePos += siteLength + 1;
siteLength = buffer[sitePos];
siteName += "." + Encoding.Default.GetString(buffer, sitePos + 1, siteLength);
info.Add(siteName + ":" + dbFile);
break;
case IscCodes.isc_info_implementation:
/* Database implementation number:
* 1 byte containing a 1
* 1 byte containing the implementation number
* 1 byte containing a class number, either 1 or 12
*/
info.Add(String.Format(CultureInfo.CurrentCulture, "{0}.{1}.{2}", buffer[pos], buffer[pos + 1], buffer[pos + 2]));
break;
case IscCodes.isc_info_no_reserve:
/* 0 or 1
* 0 indicates space is reserved on each database page for holding
* backup versions of modified records [Default]
* 1 indicates no space is reserved for such records
*/
info.Add(buffer[pos] == 1 ? true : false);
break;
case IscCodes.isc_info_ods_version:
/* ODS major version number
* Databases with different major version numbers have different
* physical layouts; a database engine can only access databases
* with a particular ODS major version number
* Trying to attach to a database with a different ODS number
* results in an error
*/
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_ods_minor_version:
/* On-disk structure (ODS) minor version number; an increase in a
* minor version number indicates a non-structural change, one that
* still allows the database to be accessed by database engines with
* the same major version number but possibly different minor
* version numbers
*/
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_page_size:
/* Number of bytes per page of the attached database; use with
* isc_info_allocation to determine the size of the database
*/
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_isc_version:
/* Version identification string of the database implementation:
* 1 byte containing the number 1
* 1 byte specifying the length, n, of the following string
* n bytes containing the version identification string
*/
info.Add(Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]));
break;
//
// Environmental characteristics
//
case IscCodes.isc_info_current_memory:
// Amount of server memory (in bytes) currently in use
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_forced_writes:
/* Number specifying the mode in which database writes are performed
* (0 for asynchronous, 1 for synchronous)
*/
info.Add(buffer[pos] == 1 ? true : false);
break;
case IscCodes.isc_info_max_memory:
/* Maximum amount of memory (in bytes) used at one time since the first
* process attached to the database
*/
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_num_buffers:
// Number of memory buffers currently allocated
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_sweep_interval:
/* Number of transactions that are committed between sweeps to
* remove database record versions that are no longer needed
*/
info.Add(VaxInteger(buffer, pos, length));
break;
//
// Performance statistics
//
case IscCodes.isc_info_fetches:
// Number of reads from the memory buffer cache
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_marks:
// Number of writes to the memory buffer cache
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_reads:
// Number of page reads
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_writes:
// Number of page writes
info.Add(VaxInteger(buffer, pos, length));
break;
//
// Database operation counts
//
case IscCodes.isc_info_backout_count:
// Number of removals of a version of a record
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_delete_count:
// Number of database deletes since the database was last attached
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_expunge_count:
/* Number of removals of a record and all of its ancestors, for records
* whose deletions have been committed
*/
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_insert_count:
// Number of inserts into the database since the database was last attached
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_purge_count:
// Number of removals of old versions of fully mature records
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_read_idx_count:
// Number of reads done via an index since the database was last attached
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_read_seq_count:
/* Number of sequential sequential table scans (row reads) done on each
* table since the database was last attached
*/
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_update_count:
// Number of database updates since the database was last attached
info.Add(VaxInteger(buffer, pos, length));
break;
//
// Misc
//
case IscCodes.isc_info_firebird_version:
info.Add(Encoding.Default.GetString(buffer, pos + 2, buffer[pos + 1]));
break;
case IscCodes.isc_info_db_class:
int serverClass = VaxInteger(buffer, pos, length);
if (serverClass == IscCodes.isc_info_db_class_classic_access)
{
info.Add("CLASSIC SERVER");
}
else
{
info.Add("SUPER SERVER");
}
break;
case IscCodes.isc_info_db_read_only:
info.Add(buffer[pos] == 1 ? true : false);
break;
case IscCodes.isc_info_db_size_in_pages:
// Database size in pages.
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_oldest_transaction:
// Number of oldest transaction
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_oldest_active:
// Number of oldest active transaction
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_oldest_snapshot:
// Number of oldest snapshot transaction
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_next_transaction:
// Number of next transaction
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_active_transactions:
// Number of active transactions
info.Add(VaxInteger(buffer, pos, length));
break;
case IscCodes.isc_info_user_names:
// Active user name
info.Add(Encoding.Default.GetString(buffer, pos + 1, buffer[pos]));
break;
}
pos += length;
}
return info;
}
public static int VaxInteger(byte[] buffer, int index, int length)
{
int newValue;
int shift;
newValue = shift = 0;
int i = index;
while (--length >= 0)
{
newValue += (buffer[i++] & 0xff) << shift;
shift += 8;
}
return newValue;
}
#endregion
}
}
|