Skip to content

Commit 3af0d27

Browse files
committed
Support for isc_info_active_tran_count (and refactoring). (#986)
1 parent f5dfe2b commit 3af0d27

File tree

3 files changed

+98
-215
lines changed

3 files changed

+98
-215
lines changed

Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscCodes.cs

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,7 +391,7 @@ internal static class IscCodes
391391
public const int isc_action_svc_remove_license = 10; /* Removes a license from the license file */
392392
public const int isc_action_svc_db_stats = 11; /* Retrieves database statistics */
393393
public const int isc_action_svc_get_ib_log = 12; /* Retrieves the InterBase log file from the server */
394-
public const int isc_action_svc_get_fb_log = 12; /* Retrieves the Firebird log file from the server */
394+
public const int isc_action_svc_get_fb_log = 12; /* Retrieves the Firebird log file from the server */
395395
public const int isc_action_svc_nbak = 20; /* Incremental nbackup */
396396
public const int isc_action_svc_nrest = 21; /* Incremental database restore */
397397
public const int isc_action_svc_trace_start = 22; // Start trace session
@@ -742,8 +742,6 @@ internal static class IscCodes
742742
public const int isc_info_db_read_only = 63;
743743
public const int isc_info_db_size_in_pages = 64;
744744

745-
/* Values 65 -100 unused to avoid conflict with InterBase */
746-
747745
public const int frb_info_att_charset = 101;
748746
public const int isc_info_db_class = 102;
749747
public const int isc_info_firebird_version = 103;
@@ -754,6 +752,58 @@ internal static class IscCodes
754752
public const int isc_info_db_provider = 108;
755753
public const int isc_info_active_transactions = 109;
756754

755+
public const int isc_info_active_tran_count = 110;
756+
public const int isc_info_creation_date = 111;
757+
public const int isc_info_db_file_size = 112;
758+
public const int fb_info_page_contents = 113;
759+
760+
public const int fb_info_implementation = 114;
761+
762+
public const int fb_info_page_warns = 115;
763+
public const int fb_info_record_warns = 116;
764+
public const int fb_info_bpage_warns = 117;
765+
public const int fb_info_dpage_warns = 118;
766+
public const int fb_info_ipage_warns = 119;
767+
public const int fb_info_ppage_warns = 120;
768+
public const int fb_info_tpage_warns = 121;
769+
public const int fb_info_pip_errors = 122;
770+
public const int fb_info_pip_warns = 123;
771+
772+
public const int fb_info_pages_used = 124;
773+
public const int fb_info_pages_free = 125;
774+
775+
public const int fb_info_ses_idle_timeout_db = 129;
776+
public const int fb_info_ses_idle_timeout_att = 130;
777+
public const int fb_info_ses_idle_timeout_run = 131;
778+
779+
public const int fb_info_conn_flags = 132;
780+
781+
public const int fb_info_crypt_key = 133;
782+
public const int fb_info_crypt_state = 134;
783+
784+
public const int fb_info_statement_timeout_db = 135;
785+
public const int fb_info_statement_timeout_att = 136;
786+
787+
public const int fb_info_protocol_version = 137;
788+
public const int fb_info_crypt_plugin = 138;
789+
790+
public const int fb_info_creation_timestamp_tz = 139;
791+
792+
public const int fb_info_wire_crypt = 140;
793+
794+
public const int fb_info_features = 141;
795+
796+
public const int fb_info_next_attachment = 142;
797+
public const int fb_info_next_statement = 143;
798+
799+
public const int fb_info_db_guid = 144;
800+
public const int fb_info_db_file_id = 145;
801+
802+
public const int fb_info_replica_mode = 146;
803+
804+
public const int fb_info_username = 147;
805+
public const int fb_info_sqlrole = 148;
806+
757807
#endregion
758808

759809
#region Information Request

Provider/src/FirebirdSql.Data.FirebirdClient/Common/IscHelper.cs

Lines changed: 36 additions & 212 deletions
Original file line numberDiff line numberDiff line change
@@ -40,30 +40,51 @@ public static List<object> ParseDatabaseInfo(byte[] buffer)
4040

4141
switch (type)
4242
{
43-
//
44-
// Database characteristics
45-
//
4643
case IscCodes.isc_info_allocation:
47-
// Number of database pages allocated
44+
case IscCodes.isc_info_ods_version:
45+
case IscCodes.isc_info_ods_minor_version:
46+
case IscCodes.isc_info_page_size:
47+
case IscCodes.isc_info_current_memory:
48+
case IscCodes.isc_info_max_memory:
49+
case IscCodes.isc_info_num_buffers:
50+
case IscCodes.isc_info_sweep_interval:
51+
case IscCodes.isc_info_fetches:
52+
case IscCodes.isc_info_marks:
53+
case IscCodes.isc_info_reads:
54+
case IscCodes.isc_info_writes:
55+
case IscCodes.isc_info_backout_count:
56+
case IscCodes.isc_info_delete_count:
57+
case IscCodes.isc_info_expunge_count:
58+
case IscCodes.isc_info_insert_count:
59+
case IscCodes.isc_info_purge_count:
60+
case IscCodes.isc_info_read_idx_count:
61+
case IscCodes.isc_info_read_seq_count:
62+
case IscCodes.isc_info_update_count:
63+
case IscCodes.isc_info_db_size_in_pages:
64+
case IscCodes.isc_info_oldest_transaction:
65+
case IscCodes.isc_info_oldest_active:
66+
case IscCodes.isc_info_oldest_snapshot:
67+
case IscCodes.isc_info_next_transaction:
68+
case IscCodes.isc_info_active_transactions:
69+
case IscCodes.isc_info_active_tran_count:
4870
info.Add(VaxInteger(buffer, pos, length));
4971
break;
5072

73+
case IscCodes.isc_info_no_reserve:
74+
case IscCodes.isc_info_forced_writes:
75+
case IscCodes.isc_info_db_read_only:
76+
info.Add(buffer[pos] == 1);
77+
break;
78+
79+
case IscCodes.isc_info_user_names:
80+
info.Add(Encoding2.Default.GetString(buffer, pos + 1, buffer[pos]));
81+
break;
82+
5183
case IscCodes.isc_info_base_level:
52-
/* Database version (level) number:
53-
* - 1 byte containing the number 1
54-
* - 1 byte containing the version number
55-
*/
5684
info.Add(string.Format(CultureInfo.CurrentCulture, "{0}.{1}", buffer[pos], buffer[pos + 1]));
5785
break;
5886

5987
case IscCodes.isc_info_db_id:
60-
/* Database file name and site name:
61-
* - 1 byte containing the number 2
62-
* - 1 byte containing the length, d, of the database file name in bytes
63-
* - A string of d bytes, containing the database file name
64-
* - 1 byte containing the length, l, of the site name in bytes
65-
* - A string of l bytes, containing the site name
66-
*/
6788
var dbFile = Encoding2.Default.GetString(buffer, pos + 2, buffer[pos + 1]);
6889
var sitePos = pos + 2 + buffer[pos + 1];
6990
int siteLength = buffer[sitePos];
@@ -77,58 +98,11 @@ public static List<object> ParseDatabaseInfo(byte[] buffer)
7798
break;
7899

79100
case IscCodes.isc_info_implementation:
80-
/* Database implementation number:
81-
* - 1 byte containing a 1
82-
* - 1 byte containing the implementation number
83-
* - 1 byte containing a class number, either 1 or 12
84-
*/
85101
info.Add(string.Format(CultureInfo.CurrentCulture, "{0}.{1}.{2}", buffer[pos], buffer[pos + 1], buffer[pos + 2]));
86102
break;
87103

88-
case IscCodes.isc_info_no_reserve:
89-
/* 0 or 1
90-
* - 0 indicates space is reserved on each database page for holding
91-
* backup versions of modified records [Default]
92-
* - 1 indicates no space is reserved for such records
93-
*/
94-
info.Add(buffer[pos] == 1 ? true : false);
95-
break;
96-
97-
case IscCodes.isc_info_ods_version:
98-
/* ODS major version number
99-
* - Databases with different major version numbers have different
100-
* physical layouts; a database engine can only access databases
101-
* with a particular ODS major version number
102-
* - Trying to attach to a database with a different ODS number
103-
* results in an error
104-
*/
105-
info.Add(VaxInteger(buffer, pos, length));
106-
break;
107-
108-
case IscCodes.isc_info_ods_minor_version:
109-
/* On-disk structure (ODS) minor version number; an increase in a
110-
* minor version number indicates a non-structural change, one that
111-
* still allows the database to be accessed by database engines with
112-
* the same major version number but possibly different minor
113-
* version numbers
114-
*/
115-
info.Add(VaxInteger(buffer, pos, length));
116-
break;
117-
118-
case IscCodes.isc_info_page_size:
119-
/* Number of bytes per page of the attached database; use with
120-
* isc_info_allocation to determine the size of the database
121-
*/
122-
info.Add(VaxInteger(buffer, pos, length));
123-
break;
124-
125104
case IscCodes.isc_info_isc_version:
126105
case IscCodes.isc_info_firebird_version:
127-
/* Version identification string of the database implementation:
128-
* - 1 byte containing the number number of message
129-
* - 1 byte specifying the length, of the following string
130-
* - n bytes containing the string
131-
*/
132106
var messagePosition = pos;
133107
var count = buffer[messagePosition];
134108
for (var i = 0; i < count; i++)
@@ -139,117 +113,6 @@ public static List<object> ParseDatabaseInfo(byte[] buffer)
139113
}
140114
break;
141115

142-
//
143-
// Environmental characteristics
144-
//
145-
146-
case IscCodes.isc_info_current_memory:
147-
// Amount of server memory (in bytes) currently in use
148-
info.Add(VaxInteger(buffer, pos, length));
149-
break;
150-
151-
case IscCodes.isc_info_forced_writes:
152-
/* Number specifying the mode in which database writes are performed
153-
* (0 for asynchronous, 1 for synchronous)
154-
*/
155-
info.Add(buffer[pos] == 1 ? true : false);
156-
break;
157-
158-
case IscCodes.isc_info_max_memory:
159-
/* Maximum amount of memory (in bytes) used at one time since the first
160-
* process attached to the database
161-
*/
162-
info.Add(VaxInteger(buffer, pos, length));
163-
break;
164-
165-
case IscCodes.isc_info_num_buffers:
166-
// Number of memory buffers currently allocated
167-
info.Add(VaxInteger(buffer, pos, length));
168-
break;
169-
170-
case IscCodes.isc_info_sweep_interval:
171-
/* Number of transactions that are committed between sweeps to
172-
* remove database record versions that are no longer needed
173-
*/
174-
info.Add(VaxInteger(buffer, pos, length));
175-
break;
176-
177-
//
178-
// Performance statistics
179-
//
180-
181-
case IscCodes.isc_info_fetches:
182-
// Number of reads from the memory buffer cache
183-
info.Add(VaxInteger(buffer, pos, length));
184-
break;
185-
186-
case IscCodes.isc_info_marks:
187-
// Number of writes to the memory buffer cache
188-
info.Add(VaxInteger(buffer, pos, length));
189-
break;
190-
191-
case IscCodes.isc_info_reads:
192-
// Number of page reads
193-
info.Add(VaxInteger(buffer, pos, length));
194-
break;
195-
196-
case IscCodes.isc_info_writes:
197-
// Number of page writes
198-
info.Add(VaxInteger(buffer, pos, length));
199-
break;
200-
201-
//
202-
// Database operation counts
203-
//
204-
205-
case IscCodes.isc_info_backout_count:
206-
// Number of removals of a version of a record
207-
info.Add(VaxInteger(buffer, pos, length));
208-
break;
209-
210-
case IscCodes.isc_info_delete_count:
211-
// Number of database deletes since the database was last attached
212-
info.Add(VaxInteger(buffer, pos, length));
213-
break;
214-
215-
case IscCodes.isc_info_expunge_count:
216-
/* Number of removals of a record and all of its ancestors, for records
217-
* whose deletions have been committed
218-
*/
219-
info.Add(VaxInteger(buffer, pos, length));
220-
break;
221-
222-
case IscCodes.isc_info_insert_count:
223-
// Number of inserts into the database since the database was last attached
224-
info.Add(VaxInteger(buffer, pos, length));
225-
break;
226-
227-
case IscCodes.isc_info_purge_count:
228-
// Number of removals of old versions of fully mature records
229-
info.Add(VaxInteger(buffer, pos, length));
230-
break;
231-
232-
case IscCodes.isc_info_read_idx_count:
233-
// Number of reads done via an index since the database was last attached
234-
info.Add(VaxInteger(buffer, pos, length));
235-
break;
236-
237-
case IscCodes.isc_info_read_seq_count:
238-
/* Number of sequential sequential table scans (row reads) done on each
239-
* table since the database was last attached
240-
*/
241-
info.Add(VaxInteger(buffer, pos, length));
242-
break;
243-
244-
case IscCodes.isc_info_update_count:
245-
// Number of database updates since the database was last attached
246-
info.Add(VaxInteger(buffer, pos, length));
247-
break;
248-
249-
//
250-
// Misc
251-
//
252-
253116
case IscCodes.isc_info_db_class:
254117
var serverClass = VaxInteger(buffer, pos, length);
255118
if (serverClass == IscCodes.isc_info_db_class_classic_access)
@@ -261,45 +124,6 @@ public static List<object> ParseDatabaseInfo(byte[] buffer)
261124
info.Add("SUPER SERVER");
262125
}
263126
break;
264-
265-
case IscCodes.isc_info_db_read_only:
266-
info.Add(buffer[pos] == 1 ? true : false);
267-
break;
268-
269-
case IscCodes.isc_info_db_size_in_pages:
270-
// Database size in pages.
271-
info.Add(VaxInteger(buffer, pos, length));
272-
break;
273-
274-
case IscCodes.isc_info_oldest_transaction:
275-
// Number of oldest transaction
276-
info.Add(VaxInteger(buffer, pos, length));
277-
break;
278-
279-
case IscCodes.isc_info_oldest_active:
280-
// Number of oldest active transaction
281-
info.Add(VaxInteger(buffer, pos, length));
282-
break;
283-
284-
case IscCodes.isc_info_oldest_snapshot:
285-
// Number of oldest snapshot transaction
286-
info.Add(VaxInteger(buffer, pos, length));
287-
break;
288-
289-
case IscCodes.isc_info_next_transaction:
290-
// Number of next transaction
291-
info.Add(VaxInteger(buffer, pos, length));
292-
break;
293-
294-
case IscCodes.isc_info_active_transactions:
295-
// Number of active transactions
296-
info.Add(VaxInteger(buffer, pos, length));
297-
break;
298-
299-
case IscCodes.isc_info_user_names:
300-
// Active user name
301-
info.Add(Encoding2.Default.GetString(buffer, pos + 1, buffer[pos]));
302-
break;
303127
}
304128

305129
pos += length;

Provider/src/FirebirdSql.Data.FirebirdClient/FirebirdClient/FbDatabaseInfo.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,15 @@ public Task<List<long>> GetActiveTransactionsAsync(CancellationToken cancellatio
350350
return GetListAsync<long>(IscCodes.isc_info_active_transactions, cancellationToken);
351351
}
352352

353+
public int GetActiveTransactionsCount()
354+
{
355+
return GetValue<int>(IscCodes.isc_info_active_tran_count);
356+
}
357+
public Task<int> GetActiveTransactionsCountAsync(CancellationToken cancellationToken = default)
358+
{
359+
return GetValueAsync<int>(IscCodes.isc_info_active_tran_count, cancellationToken);
360+
}
361+
353362
public List<string> GetActiveUsers()
354363
{
355364
return GetList<string>(IscCodes.isc_info_user_names);

0 commit comments

Comments
 (0)