18 using System.Collections.Generic;
40 TableInfoTableInfo =
new TableInfo(TableInfoTableName);
46 TableInfoTableInfo = TableInfoTableInfo.AsReadOnly();
49 TableColumnsTableInfo =
new TableInfo(TableColumnsTableName);
61 TableColumnsTableInfo = TableColumnsTableInfo.AsReadOnly();
64 VariablesTableInfo =
new TableInfo(VariablesTableName);
71 VariablesTableInfo = VariablesTableInfo.AsReadOnly();
74 ProductInfoTableInfo =
new TableInfo(ProductInfoTableName);
77 ProductInfoTableInfo = ProductInfoTableInfo.AsReadOnly();
80 StatisticsTableInfo =
new TableInfo(StatisticsTableName);
83 StatisticsTableInfo = StatisticsTableInfo.AsReadOnly();
86 SqlTypesTableInfo =
new TableInfo(SqlTypesTableName);
105 SqlTypesTableInfo = SqlTypesTableInfo.AsReadOnly();
108 OpenSessionsTableInfo =
new TableInfo(OpenSessionsTableName);
113 OpenSessionsTableInfo = OpenSessionsTableInfo.AsReadOnly();
116 SessionInfoTableInfo =
new TableInfo(SessionInfoTableName);
119 SessionInfoTableInfo = SessionInfoTableInfo.AsReadOnly();
122 PrivilegesTableInfo =
new TableInfo(PrivilegesTableName);
125 PrivilegesTableInfo = PrivilegesTableInfo.AsReadOnly();
132 public const string Name =
"SYSTEM";
239 var tableInfo =
new TableInfo(UserTableName);
242 tableInfo = tableInfo.AsReadOnly();
243 context.CreateSystemTable(tableInfo);
245 context.AddPrimaryKey(UserTableName,
new []{
"name"},
"SYSTEM_USER_PK");
247 tableInfo =
new TableInfo(PasswordTableName);
252 tableInfo = tableInfo.AsReadOnly();
253 context.CreateSystemTable(tableInfo);
255 tableInfo =
new TableInfo(UserGroupTableName);
259 tableInfo = tableInfo.AsReadOnly();
260 context.CreateSystemTable(tableInfo);
262 tableInfo =
new TableInfo(GroupsTableName);
264 tableInfo = tableInfo.AsReadOnly();
265 context.CreateSystemTable(tableInfo);
267 context.AddPrimaryKey(GroupsTableName,
new[] {
"name" },
"SYSTEM_GROUP_PK");
269 tableInfo =
new TableInfo(UserGrantsTableName);
276 tableInfo = tableInfo.AsReadOnly();
277 context.CreateSystemTable(tableInfo);
279 tableInfo =
new TableInfo(GroupGrantsTable);
287 var fkCol =
new[] {
"user"};
288 var gfkCol =
new[] {
"group"};
289 var refCol =
new[] {
"name"};
292 context.AddForeignKey(PasswordTableName, fkCol, UserTableName, refCol, onDelete, onUpdate,
"USER_PASSWORD_FK");
293 context.AddForeignKey(UserGroupTableName, fkCol, UserTableName, refCol, onDelete, onUpdate,
"USER_PRIV_FK");
294 context.AddForeignKey(UserGroupTableName, gfkCol, GroupsTableName, refCol, onDelete, onUpdate,
"USER_GROUP_FK");
295 context.AddForeignKey(UserGrantsTableName, fkCol, UserTableName, refCol, onDelete, onUpdate,
"USER_GRANTS_FK");
296 context.AddForeignKey(GroupGrantsTable, gfkCol, GroupsTableName, refCol, onDelete, onUpdate,
"GROUP_GRANTS_FK");
330 CreateSecurityTables(context);
348 var idCol =
new[] {
"id" };
349 transaction.AddPrimaryKey(PrimaryKeyInfoTableName, idCol,
"SYSTEM_PK_PK");
350 transaction.AddPrimaryKey(ForeignKeyInfoTableName, idCol,
"SYSTEM_FK_PK");
351 transaction.AddPrimaryKey(UniqueKeyInfoTableName, idCol,
"SYSTEM_UNIQUE_PK");
352 transaction.AddPrimaryKey(CheckInfoTableName, idCol,
"SYSTEM_CHECK_PK");
353 transaction.AddPrimaryKey(SchemaInfoTableName, idCol,
"SYSTEM_SCHEMA_PK");
357 var fkCol =
new string[1];
358 var fkRefCol =
new[] {
"id" };
361 transaction.AddForeignKey(PrimaryKeyColumnsTableName, fkCol, PrimaryKeyInfoTableName, fkRefCol,
"SYSTEM_PK_FK");
364 transaction.AddForeignKey(ForeignKeyColumnsTableName, fkCol, ForeignKeyInfoTableName, fkRefCol,
"SYSTEM_FK_FK");
367 transaction.AddForeignKey(UniqueKeyColumnsTableName, fkCol, UniqueKeyInfoTableName, fkRefCol,
"SYSTEM_UNIQUE_FK");
371 var columns =
new[] {
"schema",
"table" };
372 transaction.AddUniqueKey(PrimaryKeyInfoTableName, columns,
"SYSTEM_PKEY_ST_UNIQUE");
375 columns =
new String[] {
"name" };
376 transaction.AddUniqueKey(SchemaInfoTableName, columns,
"SYSTEM_SCHEMA_UNIQUE");
379 columns =
new String[] {
"name",
"schema" };
381 transaction.AddUniqueKey(PrimaryKeyInfoTableName, columns,
"SYSTEM_PKEY_UNIQUE");
384 transaction.AddUniqueKey(ForeignKeyInfoTableName, columns,
"SYSTEM_FKEY_UNIQUE");
387 transaction.AddUniqueKey(UniqueKeyInfoTableName, columns,
"SYSTEM_UNIQUE_UNIQUE");
390 transaction.AddUniqueKey(CheckInfoTableName, columns,
"SYSTEM_CHECK_UNIQUE");
429 #region TableInfoTable
438 tableInfoObjects =
new List<TableInfoObject>();
446 get {
return TableInfoTableInfo; }
449 public override int RowCount {
450 get {
return rowCount; }
456 var tableNames = manager.GetTableNames();
458 var tableList = tableNames.ToArray();
459 Array.Sort(tableList);
460 rowCount = tableList.Length;
462 foreach (var tableName
in tableList) {
463 string curType =
Transaction.GetTableType(tableName);
467 if (curType.Equals(
"TABLE") &&
468 tableName.Parent.Name.Equals(Name)) {
469 curType =
"SYSTEM TABLE";
472 tableInfoObjects.Add(
new TableInfoObject(null, tableName.Parent.Name, tableName.Name, curType, null));
477 if (rowNumber < 0 || rowNumber >= tableInfoObjects.Count)
478 throw new ArgumentOutOfRangeException(
"rowNumber");
480 var tableInfo = tableInfoObjects[(int) rowNumber];
482 switch (columnOffset) {
494 throw new ArgumentOutOfRangeException(
"columnOffset");
498 #region TableInfoObject
501 public TableInfoObject(
string catalog,
string schema,
string name,
string type,
string comments) {
509 public string Name {
get;
private set; }
510 public string Schema {
get;
private set; }
511 public string Catalog {
get;
private set; }
512 public string Type {
get;
private set; }
513 public string Comments {
get;
private set; }
520 #region TableColumnsTable
527 this.transaction = transaction;
531 get {
return TableColumnsTableInfo; }
534 public override int RowCount {
535 get {
return GetRowCount(); }
540 var tableManager = transaction.GetTableManager();
541 var list = tableManager.GetTableNames();
544 foreach (var tableName
in list) {
545 var info = tableManager.GetTableInfo(tableName);
547 throw new InvalidOperationException(
String.Format(
"Table information not found for '{0}'.", tableName));
549 colCount += info.ColumnCount;
557 var tableManager = transaction.GetTableManager();
558 var list = tableManager.GetTableNames();
559 var visibleTables = list.Select(name => transaction.GetTableInfo(name));
562 foreach (var info
in visibleTables) {
563 var schemaName = info.SchemaName == null ? null : info.SchemaName.FullName;
566 rs += info.ColumnCount;
567 if (rowNumber >= b && rowNumber < rs) {
569 var seqNo = rowNumber - b;
570 var colInfo = info[(int)seqNo];
572 var defaultExpression = colInfo.HasDefaultExpression ? colInfo.DefaultExpression.ToString() : null;
574 switch (columnOffset) {
576 return GetColumnValue(columnOffset,
new SqlString(schemaName));
578 return GetColumnValue(columnOffset,
new SqlString(info.Name));
580 return GetColumnValue(columnOffset,
new SqlString(colInfo.ColumnName));
582 return GetColumnValue(columnOffset,
new SqlNumber((
int)colInfo.ColumnType.TypeCode));
584 return GetColumnValue(columnOffset,
new SqlString(colInfo.ColumnType.ToString()));
586 return GetColumnValue(columnOffset,
new SqlNumber(colInfo.Size));
588 return GetColumnValue(columnOffset,
new SqlNumber(colInfo.Scale));
590 return GetColumnValue(columnOffset, (
SqlBoolean) colInfo.IsNotNull);
592 return GetColumnValue(columnOffset,
new SqlString(defaultExpression));
594 return GetColumnValue(columnOffset,
new SqlString(colInfo.IndexType));
596 return GetColumnValue(columnOffset,
new SqlNumber(seqNo));
598 throw new ArgumentOutOfRangeException(
"columnOffset");
604 throw new ArgumentOutOfRangeException(
"rowNumber",
"Row out of bounds.");
607 protected override void Dispose(
bool disposing) {
609 base.Dispose(disposing);
615 #region SqlTypesTable
623 this.transaction = transaction;
625 sqlTypes =
new List<SqlTypeInfo>();
631 get {
return SqlTypesTableInfo; }
634 public override int RowCount {
635 get {
return sqlTypes.Count; }
638 private void AddType(
string name,
string localName,
SqlTypeCode type, byte precision,
string prefix,
string suffix,
bool searchable) {
641 LocalName = localName,
643 Precision = precision,
644 LiteralPrefix = prefix,
645 LiteralSuffix = suffix,
646 Searchable = (byte)(searchable ? 3 : 0)
651 AddType(
"BIT",
"BOOLEAN",
SqlTypeCode.Bit, 1, null, null,
true);
652 AddType(
"BOOLEAN",
"BOOLEAN",
SqlTypeCode.Boolean, 1, null, null,
true);
653 AddType(
"TINYINT",
"NUMBER",
SqlTypeCode.TinyInt, 9, null, null,
true);
654 AddType(
"SMALLINT",
"NUMBER",
SqlTypeCode.SmallInt, 9, null, null,
true);
655 AddType(
"INTEGER",
"NUMBER",
SqlTypeCode.Integer, 9, null, null,
true);
656 AddType(
"BIGINT",
"NUMBER",
SqlTypeCode.BigInt, 9, null, null,
true);
657 AddType(
"FLOAT",
"NUMBER",
SqlTypeCode.Float, 9, null, null,
true);
658 AddType(
"REAL",
"NUMBER",
SqlTypeCode.Real, 9, null, null,
true);
659 AddType(
"DOUBLE",
"NUMBER",
SqlTypeCode.Double, 9, null, null,
true);
660 AddType(
"NUMERIC",
"NUMBER",
SqlTypeCode.Numeric, 9, null, null,
true);
661 AddType(
"DECIMAL",
"NUMBER",
SqlTypeCode.Decimal, 9, null, null,
true);
662 AddType(
"CHAR",
"STRING",
SqlTypeCode.Char, 9,
"'",
"'",
true);
663 AddType(
"VARCHAR",
"STRING",
SqlTypeCode.VarChar, 9,
"'",
"'",
true);
664 AddType(
"LONGVARCHAR",
"STRING",
SqlTypeCode.LongVarChar, 9,
"'",
"'",
true);
665 AddType(
"DATE",
"DATETIME",
SqlTypeCode.Date, 9, null, null,
true);
666 AddType(
"TIME",
"DATETIME",
SqlTypeCode.Time, 9, null, null,
true);
667 AddType(
"TIMESTAMP",
"DATETIME",
SqlTypeCode.TimeStamp, 9, null, null,
true);
668 AddType(
"BINARY",
"BINARY",
SqlTypeCode.Binary, 9, null, null,
false);
669 AddType(
"VARBINARY",
"BINARY",
SqlTypeCode.VarBinary, 9, null, null,
false);
670 AddType(
"LONGVARBINARY",
"BINARY",
SqlTypeCode.LongVarBinary, 9, null, null,
false);
671 AddType(
"OBJECT",
"OBJECT",
SqlTypeCode.Object, 9, null, null,
false);
672 AddType(
"TYPE",
"TYPE",
SqlTypeCode.Type, 9, null, null,
false);
678 if (rowNumber < 0 || rowNumber >= sqlTypes.Count)
679 throw new ArgumentOutOfRangeException(
"rowNumber");
681 var typeInfo = sqlTypes[(int)rowNumber];
682 switch (columnOffset) {
684 return GetColumnValue(columnOffset,
new SqlString(typeInfo.TypeName));
686 return GetColumnValue(columnOffset,
new SqlNumber((
int)typeInfo.Type));
688 return GetColumnValue(columnOffset,
new SqlNumber(typeInfo.Precision));
690 return GetColumnValue(columnOffset,
new SqlString(typeInfo.LiteralPrefix));
692 return GetColumnValue(columnOffset,
new SqlString(typeInfo.LiteralSuffix));
694 return GetColumnValue(columnOffset,
SqlString.Null);
698 return GetColumnValue(columnOffset,
SqlBoolean.True);
700 return GetColumnValue(columnOffset,
new SqlNumber(typeInfo.Searchable));
702 return GetColumnValue(columnOffset,
SqlBoolean.False);
704 return GetColumnValue(columnOffset,
SqlBoolean.False);
706 return GetColumnValue(columnOffset,
SqlBoolean.False);
708 return GetColumnValue(columnOffset,
new SqlString(typeInfo.LocalName));
712 return GetColumnValue(columnOffset,
new SqlNumber(10000000));
718 return GetColumnValue(columnOffset,
new SqlNumber(10));
720 throw new ArgumentOutOfRangeException(
"columnOffset");
725 protected override void Dispose(
bool disposing) {
729 base.Dispose(disposing);
749 #region OpenSessionsTable
756 this.transaction = transaction;
760 get {
return OpenSessionsTableInfo; }
763 public override int RowCount {
769 throw new ArgumentOutOfRangeException(
"rowNumber");
772 var lastCommandTime = session.LastCommandTime == null
776 switch (columnOffset) {
778 return GetColumnValue(0,
new SqlString(session.User.Name));
780 return GetColumnValue(1,
SqlString.Null);
782 return GetColumnValue(2, lastCommandTime);
784 return GetColumnValue(3, (
SqlDateTime)session.StartedOn);
786 throw new ArgumentOutOfRangeException(
"columnOffset");
790 protected override void Dispose(
bool disposing) {
792 base.Dispose(disposing);
798 #region ProductInfoTable
809 get {
return ProductInfoTableInfo; }
812 public override int RowCount {
813 get {
return keyValuePairs.Count/2; }
817 keyValuePairs =
new List<ISqlString>();
822 keyValuePairs.Add(
new SqlString(
"title"));
823 keyValuePairs.Add(
new SqlString(productInfo.Title));
825 keyValuePairs.Add(
new SqlString(
"version"));
826 keyValuePairs.Add(
new SqlString(productInfo.Version.ToString()));
828 keyValuePairs.Add(
new SqlString(
"copyright"));
829 keyValuePairs.Add(
new SqlString(productInfo.Copyright));
831 keyValuePairs.Add(
new SqlString(
"description"));
832 keyValuePairs.Add(
new SqlString(productInfo.Description));
834 keyValuePairs.Add(
new SqlString(
"company"));
835 keyValuePairs.Add(
new SqlString(productInfo.Company));
839 switch (columnOffset) {
841 return GetColumnValue(columnOffset, keyValuePairs[(
int)rowNumber * 2]);
843 return GetColumnValue(columnOffset, keyValuePairs[(
int)(rowNumber * 2) + 1]);
845 throw new ArgumentOutOfRangeException(
"columnOffset");
852 #region VariablesTable
859 this.transaction = transaction;
863 get {
return VariablesTableInfo; }
866 public override int RowCount {
867 get {
throw new NotImplementedException(); }
871 throw new NotImplementedException();
874 protected override void Dispose(
bool disposing) {
876 base.Dispose(disposing);
882 #region PrivilegesTable
885 private readonly IList<KeyValuePair<string, int>>
privBits;
889 privBits = FormPrivilegesValues();
893 var names = Enum.GetNames(typeof (
Privileges));
894 var values = Enum.GetValues(typeof (
Privileges));
896 return names.Select((t, i) =>
new KeyValuePair<string, int>(t, (
int) values.GetValue(i))).ToList();
900 get {
return PrivilegesTableInfo; }
903 public override int RowCount {
904 get {
return privBits.Count; }
908 if (rowNumber < 0 || rowNumber >= privBits.Count)
909 throw new ArgumentOutOfRangeException(
"rowNumber");
911 var pair = privBits[(int) rowNumber];
912 switch (columnOffset) {
918 throw new ArgumentOutOfRangeException(
"columnOffset");
925 #region SessionInfoTable
933 get {
throw new NotImplementedException(); }
936 public override int RowCount {
937 get {
throw new NotImplementedException(); }
941 throw new NotImplementedException();
947 #region StatisticsTable
955 get {
throw new NotImplementedException(); }
958 public override int RowCount {
959 get {
throw new NotImplementedException(); }
963 throw new NotImplementedException();
Provides some helper functions for resolving and creating SqlType instances that are primitive to the...
static readonly TableInfo SqlTypesTableInfo
static ITable GetPrivilegesTable(ITransaction transaction)
static void Setup(ITransaction transaction)
static DataObject Integer(int value)
Defines the contract to access the data contained into a table of a database.
static void CreateTables(IQuery context)
static ITable GetOpenSessionsTable(ITransaction transaction)
readonly IList< KeyValuePair< string, int > > privBits
TableColumnsTable(ITransaction transaction)
A long string in the system.
The system implementation of a transaction model that handles isolated operations within a database c...
override void Dispose(bool disposing)
static ITable GetSqlTypesTable(ITransaction transaction)
const string PublicName
The name of the PUBLIC special user.
static void CreateSecurityTables(IQuery context)
TableInfoTable(ITransaction transaction)
static BooleanType Boolean()
override void Dispose(bool disposing)
static readonly TableInfo TableInfoTableInfo
SqlTypesTable(ITransaction transaction)
static BinaryType Binary(int maxSize)
TableInfoObject(string catalog, string schema, string name, string type, string comments)
The default implementation of a database in a system.
Describes the name of an object within a database.
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
IDatabase Database
Gets the database this transaction belongs to.
static readonly TableInfo TableColumnsTableInfo
override void Dispose(bool disposing)
static ITable GetVariablesTable(ITransaction transaction)
static DataObject String(string s)
static readonly TableInfo PrivilegesTableInfo
List< SqlTypeInfo > sqlTypes
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
static readonly SqlNull Value
ForeignKeyAction
Enumerates the foreign key referential trigger actions.
static ITable GetStatisticsTable(ITransaction transaction)
static readonly TableInfo ProductInfoTableInfo
A user-defined TYPE that holds complex objects in a database column.
VariablesTable(ITransaction transaction)
static readonly SqlNumber Zero
An isolated session to a given database for a given user, encapsulating the transaction for operation...
static NumericType Numeric()
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
static readonly TableInfo StatisticsTableInfo
static void GrantToPublic(IQuery context)
Represents a dynamic object that encapsulates a defined SqlType and a compatible constant ISqlObject ...
static DateType DateTime()
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
ProductInfoTable(ITransaction transaction)
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
static readonly TableInfo VariablesTableInfo
static readonly SqlDateTime Null
int Count
Gets the count of the open connections.
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
SessionInfoTable(ISession session)
Provides utilities and properties for handling the SYSTEN schema of a database.
A SCHEMA object, that is a named container of multiple types of objects (eg. TABLE, PROCEDURE, VIEW, etc.).
static readonly TableInfo OpenSessionsTableInfo
IList< KeyValuePair< string, int > > FormPrivilegesValues()
SqlTypeCode
Enumerates the codes of all SQL types handled by the system.
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
ActiveSessionList Sessions
Gets a list of all the open sessions to the database.
List< TableInfoObject > tableInfoObjects
static DataObject VarChar(string s)
static readonly SqlNumber One
static StringType String()
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...
PrivilegesTable(ITransaction transaction)
void AddType(string name, string localName, SqlTypeCode type, byte precision, string prefix, string suffix, bool searchable)
override void Dispose(bool disposing)
The simplest implementation of a transaction.
static ITable GetSessionInfoTable(IQuery context)
Defines the metadata properties of a table existing within a database.
List< ISqlString > keyValuePairs
static ITable GetTableColumnsTable(ITransaction transaction)
Provides the information for a user in a database system
OpenSessionsTable(ITransaction transaction)
static ITable GetTableInfoTable(ITransaction transaction)
static readonly TableInfo SessionInfoTableInfo
Deveel.Data.Sql.Objects.SqlString SqlString
static ITable GetProductInfoTable(ITransaction transaction)
static ProductInfo Current
StatisticsTable(ITransaction transaction)
override DataObject GetValue(long rowNumber, int columnOffset)
Gets a single cell within the table that is located at the given column offset and row...