public TableQueryInfo(IUserSession session, TableInfo tableInfo, ObjectName tableName, ObjectName aliasName)
 {
     Session = session;
     TableInfo = tableInfo;
     TableName = tableName;
     AliasName = aliasName;
 }
Example #2
0
        static SessionTableContainer()
        {
            // SYSTEM.OPEN_SESSIONS
            OpenSessionsTableInfo = new TableInfo(SystemSchema.OpenSessionsTableName);
            OpenSessionsTableInfo.AddColumn("username", PrimitiveTypes.String());
            OpenSessionsTableInfo.AddColumn("host_string", PrimitiveTypes.String());
            OpenSessionsTableInfo.AddColumn("last_command", PrimitiveTypes.DateTime());
            OpenSessionsTableInfo.AddColumn("time_connected", PrimitiveTypes.DateTime());
            OpenSessionsTableInfo = OpenSessionsTableInfo.AsReadOnly();

            // SYSTEM.SESSION_INFO
            SessionInfoTableInfo = new TableInfo(SystemSchema.SessionInfoTableName);
            SessionInfoTableInfo.AddColumn("var", PrimitiveTypes.String());
            SessionInfoTableInfo.AddColumn("value", PrimitiveTypes.String());
            SessionInfoTableInfo = SessionInfoTableInfo.AsReadOnly();

            // SYSTEM.STATS
            StatisticsTableInfo = new TableInfo(SystemSchema.StatisticsTableName);
            StatisticsTableInfo.AddColumn("stat_name", PrimitiveTypes.String());
            StatisticsTableInfo.AddColumn("value", PrimitiveTypes.String());
            StatisticsTableInfo = StatisticsTableInfo.AsReadOnly();

            IntTableInfo = new TableInfo[3];
            IntTableInfo[0] = StatisticsTableInfo;
            IntTableInfo[1] = SessionInfoTableInfo;
            IntTableInfo[2] = OpenSessionsTableInfo;
        }
Example #3
0
        public void Create()
        {
            // SYSTEM.ROUTINE
            var tableInfo = new TableInfo(SystemSchema.RoutineTableName);
            tableInfo.AddColumn("schema", PrimitiveTypes.String());
            tableInfo.AddColumn("name", PrimitiveTypes.String());
            tableInfo.AddColumn("type", PrimitiveTypes.String());
            tableInfo.AddColumn("location", PrimitiveTypes.String());
            tableInfo.AddColumn("return_type", PrimitiveTypes.String());
            tableInfo.AddColumn("username", PrimitiveTypes.String());
            transaction.CreateTable(tableInfo);

            // SYSTEM.ROUTINE_PARAM
            tableInfo = new TableInfo(SystemSchema.RoutineParameterTableName);
            tableInfo.AddColumn("schema", PrimitiveTypes.String());
            tableInfo.AddColumn("name", PrimitiveTypes.String());
            tableInfo.AddColumn("arg_name", PrimitiveTypes.String());
            tableInfo.AddColumn("arg_type", PrimitiveTypes.String());
            tableInfo.AddColumn("in_out", PrimitiveTypes.String());
            tableInfo.AddColumn("offset", PrimitiveTypes.Integer());
            transaction.CreateTable(tableInfo);

            var fkCol = new[] {"routine_schema", "routine_name"};
            var refCol = new[] {"schema", "name"};
            const ForeignKeyAction onUpdate = ForeignKeyAction.NoAction;
            const ForeignKeyAction onDelete = ForeignKeyAction.Cascade;

            transaction.AddForeignKey(SystemSchema.RoutineParameterTableName, fkCol, SystemSchema.RoutineTableName, refCol,
                onDelete, onUpdate, "ROUTINE_PARAMS_FK");
        }
Example #4
0
		public override string GetAutoIncrementExpression(TableInfo ti)
		{
			if (!string.IsNullOrEmpty(ti.SequenceName))
				return string.Format("{0}.nextval", ti.SequenceName);

			return null;
		}
        public void TestSetup()
        {
            var tableInfo = new TableInfo(ObjectName.Parse("APP.people"));
            tableInfo.AddColumn("id", PrimitiveTypes.Bit());
            tableInfo.AddColumn("first_name", PrimitiveTypes.String(), true);
            tableInfo.AddColumn("last_name", PrimitiveTypes.String());
            tableInfo.AddColumn("age", PrimitiveTypes.TinyInt());
            table = new TemporaryTable(tableInfo);

            var tempTable = (TemporaryTable) table;
            tempTable.NewRow(new[] {
                DataObject.BigInt(1),
                DataObject.String("Antonello"),
                DataObject.String("Provenzano"),
                DataObject.Null()
            });
            tempTable.NewRow(new[] {
                DataObject.BigInt(2),
                DataObject.String("Moritz"),
                DataObject.String("Krull"),
                DataObject.TinyInt(31)
            });

            tempTable.BuildIndexes();
        }
Example #6
0
        protected override ISession CreateAdminSession(IDatabase database)
        {
            using (var session = base.CreateAdminSession(database)) {
                using (var query = session.CreateQuery()) {
                    var tn1 = ObjectName.Parse("APP.test_table1");
                    var tableInfo1 = new TableInfo(tn1);
                    tableInfo1.AddColumn(new ColumnInfo("id", PrimitiveTypes.Integer()));
                    tableInfo1.AddColumn(new ColumnInfo("name", PrimitiveTypes.String()));
                    tableInfo1.AddColumn(new ColumnInfo("date", PrimitiveTypes.DateTime()));
                    query.CreateTable(tableInfo1);
                    query.AddPrimaryKey(tn1, "id");

                    var tn2 = ObjectName.Parse("APP.test_table2");
                    var tableInfo2 = new TableInfo(tn2);
                    tableInfo2.AddColumn(new ColumnInfo("id", PrimitiveTypes.Integer()));
                    tableInfo2.AddColumn(new ColumnInfo("other_id", PrimitiveTypes.Integer()));
                    tableInfo2.AddColumn(new ColumnInfo("count", PrimitiveTypes.Integer()));
                    query.CreateTable(tableInfo2);
                    query.AddPrimaryKey(tn2, "id");
                    query.AddForeignKey(tn2, new[] { "other_id" }, tn1, new[] { "id" }, ForeignKeyAction.Cascade, ForeignKeyAction.Cascade, null);

                    query.Commit();
                }
            }

            return base.CreateAdminSession(database);
        }
Example #7
0
        protected override void DoRun()
        {
            var tables = Connection.GetSchema("Tables");
            var columns = new List<DataRow>();
            foreach (DataRow row in Connection.GetSchema("Columns").Rows) columns.Add(row);
            columns = new List<DataRow>(columns.SortedByKey<DataRow, int>(c => c.SafeInt("ORDINAL_POSITION")));

            foreach (DataRow row in tables.Rows)
            {
                if (row.SafeString("TABLE_TYPE") != "BASE TABLE") continue;
                var table = new TableInfo(Result);
                table.FullName = new NameWithSchema(row.SafeString("TABLE_SCHEMA"), row.SafeString("TABLE_NAME"));
                Result.Tables.Add(table);
                _tables[table.FullName] = table;
            }

            foreach (DataRow row in columns)
            {
                if (row.SafeString("TABLE_TYPE") != "BASE TABLE") continue;
                var tname = new NameWithSchema(row.SafeString("TABLE_SCHEMA"), row.SafeString("TABLE_NAME"));
                var table = _tables[tname];
                var col = new ColumnInfo(table);
                col.Name = row.SafeString("COLUMN_NAME");
                col.NotNull = row.SafeString("IS_NULLABLE") == "NO";
                col.DataType = row.SafeString("DATA_TYPE");
                col.Length = row.SafeInt("CHARACTER_MAXIMUM_LENGTH");
                col.Precision = row.SafeInt("NUMERIC_PRECISION");
                col.Scale = row.SafeInt("NUMERIC_SCALE");
                col.DefaultValue = row.SafeString("COLUMN_DEFAULT");
                table.Columns.Add(col);
            }
        }
Example #8
0
        public void CreateSimpleTableAsAdmin()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var tableInfo = new TableInfo(tableName);
            tableInfo.AddColumn("a", PrimitiveTypes.Integer(), true);
            tableInfo.AddColumn("b", PrimitiveTypes.String());

            using (var session = Database.CreateUserSession(AdminUserName, AdminPassword)) {
                using (var context = new SessionQueryContext(session)) {
                    Assert.DoesNotThrow(() => {
                        context.CreateTable(tableInfo);
                    });
                }

                Assert.DoesNotThrow(() => session.Commit());
            }

            using (var session = Database.CreateUserSession(AdminUserName, AdminPassword)) {
                using (var context = new SessionQueryContext(session)) {
                    bool exists = false;
                    Assert.DoesNotThrow(() => exists = context.TableExists(tableName));
                    Assert.IsTrue(exists);
                }
            }
        }
    internal static TableInfo GetTableInfo( Type t )
    {
      TableInfo table;
      if ( _tableNameCache.TryGetValue( t, out table ) ) return table;

      table = new TableInfo();
      table.TableName = t.Name;
      table.SchemaName = "dbo";

      // check for an attribute specifying something different
      var tableAttribute = t.GetCustomAttribute<TableAttribute>( false );
      if ( tableAttribute != null )
      {
        table.TableName = tableAttribute.Name;
        if ( !string.IsNullOrWhiteSpace( tableAttribute.Schema ) ) table.SchemaName = tableAttribute.Schema;
      }

      // get the property names that can be mapped
      foreach ( var pi in t.GetProperties( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public ).Where( m => m.CanRead && m.CanWrite && !m.HasCustomAttribute<NotMappedAttribute>( false ) ) )
        table.FieldNames.Add( GetFieldName( pi ) );

      // get the key property names
      foreach ( var pi in t.GetProperties( System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public ).Where( m => m.CanRead && m.CanWrite && m.HasCustomAttribute<System.ComponentModel.DataAnnotations.KeyAttribute>( false )  ) )
        table.PrimaryKeyFieldNames.Add( GetFieldName( pi ) );

      // try to add the newly aquired info
      if ( _tableNameCache.TryAdd( t, table ) ) return table;
      return _tableNameCache[ t ];
    }
        public IObjectInfo CreateObjectInfo(Type forType)
        {
            if (forType == null)
            {
                throw new ArgumentNullException("forType");
            }

            var tableAttribute = forType.GetAttribute<TableAttribute>(inherit: false);

            if (tableAttribute == null)
            {
                throw new MappingException(ExceptionMessages.AttributeMappingConvention_NoTableAttribute.FormatWith(forType.FullName));
            }

            var identifierStrategy = IdentifierStrategy.DbGenerated;
            var columns = this.CreateColumnInfos(forType, ref identifierStrategy);

            var tableInfo = new TableInfo(columns, identifierStrategy, tableAttribute.Name, tableAttribute.Schema);

            if (this.log.IsDebug)
            {
                this.log.Debug(LogMessages.MappingConvention_MappingTypeToTable, forType.FullName, tableInfo.Schema, tableInfo.Name);
            }

            return new PocoObjectInfo(forType, tableInfo);
        }
Example #11
0
        public static string GetDeleteByIdSql(TableInfo tableInfo)
        {
            string strSql = "delete from {0} where {1} =" + AdoHelper.DbParmChar + tableInfo.Id.Key;
            strSql = string.Format(strSql, tableInfo.TableName, tableInfo.Id.Key);

            return strSql;
        }
 private void CreateTable(IQuery query)
 {
     var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
     tableInfo.AddColumn("a", PrimitiveTypes.Integer());
     tableInfo.AddColumn("b", PrimitiveTypes.String(), false);
     query.CreateTable(tableInfo, false, false);
 }
Example #13
0
        protected override bool OnSetUp(string testName, IQuery query)
        {
            var tableInfo = new TableInfo(ObjectName.Parse("APP.test_table"));
            tableInfo.AddColumn("a", PrimitiveTypes.Integer());

            query.Access().CreateObject(tableInfo);
            return true;
        }
        public TableInfoListViewItem(TableInfo table)
        {
            this.Table = table;
            if (table == null) return;

            this.Name = table.Name;
            this.Text = $"{table.Name} ({table.TotalRecords})";
        }
Example #15
0
 private bool IsTableDropped(IEnumerable<RelationalModelChange> changes, TableInfo table)
 {
     return CollectionUtils.Contains(changes,
         delegate(RelationalModelChange c)
         {
             return c is DropTableChange && Equals(c.Table, table);
         });
 }
Example #16
0
 public void GetTableInfo(Type t, TableInfo ti)
 {
     if (t == typeof(Poco2))
     {
         ti.TableName = "petapoco";
         ti.PrimaryKey = "id";
     }
 }
Example #17
0
        public ForeignKeyBuilder(string name, TableInfo referencedTable)
            : base(name)
        {
            targetTable = referencedTable.Name;
              targetColName = referencedTable.PrimaryKeyName;

              base.colType = referencedTable.PrimaryKeyType;
              base.size = referencedTable.PrimaryKeySize;
        }
Example #18
0
        public FunctionTable(ITable table, SqlExpression[] functionList, string[] columnNames, IRequest queryContext)
            : base(queryContext.Context)
        {
            // Make sure we are synchronized over the class.
            lock (typeof(FunctionTable)) {
                uniqueId = uniqueKeySeq;
                ++uniqueKeySeq;
            }

            uniqueId = (uniqueId & 0x0FFFFFFF) | 0x010000000;

            context = queryContext;

            ReferenceTable = table;
            varResolver = table.GetVariableResolver();
            varResolver = varResolver.ForRow(0);

            // Create a DataTableInfo object for this function table.
            funTableInfo = new TableInfo(FunctionTableName);

            expList = new SqlExpression[functionList.Length];
            expInfo = new byte[functionList.Length];

            // Create a new DataColumnInfo for each expression, and work out if the
            // expression is simple or not.
            for (int i = 0; i < functionList.Length; ++i) {
                var expr = functionList[i];
                // Examine the expression and determine if it is simple or not
                if (expr.IsConstant() && !expr.HasAggregate(context)) {
                    // If expression is a constant, solve it
                    var result = expr.Evaluate(context, null);
                    if (result.ExpressionType != SqlExpressionType.Constant)
                        throw new InvalidOperationException();

                    expr = result;
                    expList[i] = expr;
                    expInfo[i] = 1;
                } else {
                    // Otherwise must be dynamic
                    expList[i] = expr;
                    expInfo[i] = 0;
                }

                // Make the column info
                funTableInfo.AddColumn(columnNames[i], expr.ReturnType(context, varResolver));
            }

            // Make sure the table info isn't changed from this point on.
            funTableInfo = funTableInfo.AsReadOnly();

            // routine tables are the size of the referring table.
            rowCount = table.RowCount;

            // Set schemes to 'blind search'.
            SetupIndexes(DefaultIndexTypes.BlindSearch);
        }
        public void Ctor_Sets_JsonConverter_And_TableInfo()
        {
            var jsonConverter = new JilJsonConverter();
            var info = new TableInfo();

            var convention = new StoreConventions(jsonConverter, info);

            convention.JsonConverter.ShouldBeSameAs(jsonConverter);
            convention.TableInfo.ShouldBeSameAs(info);
        }
Example #20
0
 protected override IQuery CreateQuery(ISession session)
 {
     var query = base.CreateQuery(session);
     var tableInfo = new TableInfo(TestTableName);
     tableInfo.AddColumn("id", PrimitiveTypes.Integer());
     tableInfo.AddColumn("name", PrimitiveTypes.String());
     tableInfo.AddColumn("date", PrimitiveTypes.DateTime());
     query.CreateTable(tableInfo);
     return query;
 }
Example #21
0
        public ViewInfo(TableInfo tableInfo, SqlQueryExpression queryExpression, IQueryPlanNode queryPlan)
        {
            if (tableInfo == null)
                throw new ArgumentNullException("tableInfo");
            if (queryExpression == null)
                throw new ArgumentNullException("queryExpression");

            TableInfo = tableInfo;
            QueryExpression = queryExpression;
            QueryPlan = queryPlan;
        }
Example #22
0
        protected override IQueryContext CreateQueryContext(IDatabase database)
        {
            var context = base.CreateQueryContext(database);

            var tableInfo = new TableInfo(TestTableName);
            tableInfo.AddColumn("id", PrimitiveTypes.Integer());
            tableInfo.AddColumn("name", PrimitiveTypes.String());
            tableInfo.AddColumn("date", PrimitiveTypes.DateTime());

            return context;
        }
        private IMutableTable CreateTable()
        {
            var tableName = ObjectName.Parse("APP.test_table");
            var tableInfo = new TableInfo(tableName);
            tableInfo.AddColumn("name", PrimitiveTypes.String(), true);
            tableInfo.AddColumn("age", PrimitiveTypes.Integer());
            tableInfo.AddColumn("order", PrimitiveTypes.Integer());

            Query.CreateTable(tableInfo);
            return Query.GetMutableTable(tableName);
        }
Example #24
0
 public void Create()
 {
     // SYSTEM.SCHEMA_INFO
     var tableInfo = new TableInfo(SystemSchema.SchemaInfoTableName);
     tableInfo.AddColumn("id", PrimitiveTypes.Numeric());
     tableInfo.AddColumn("name", PrimitiveTypes.String());
     tableInfo.AddColumn("type", PrimitiveTypes.String());
     tableInfo.AddColumn("culture", PrimitiveTypes.String());
     tableInfo.AddColumn("other", PrimitiveTypes.String());
     tableInfo = tableInfo.AsReadOnly();
     Transaction.CreateTable(tableInfo);
 }
Example #25
0
 public void OnTableCompositeSetup(IQuery systemQuery)
 {
     var tableInfo = new TableInfo(SystemSchema.GrantsTableName);
     tableInfo.AddColumn("priv_bit", PrimitiveTypes.Numeric());
     tableInfo.AddColumn("object", PrimitiveTypes.Numeric());
     tableInfo.AddColumn("name", PrimitiveTypes.String());
     tableInfo.AddColumn("grantee", PrimitiveTypes.String());
     tableInfo.AddColumn("grant_option", PrimitiveTypes.Boolean());
     tableInfo.AddColumn("granter", PrimitiveTypes.String());
     tableInfo = tableInfo.AsReadOnly();
     systemQuery.Access().CreateSystemTable(tableInfo);
 }
Example #26
0
        public static IFields CreateFields(TableInfo tInfo)
        {
            if (tInfo == null || tInfo.FieldsInfo == null || tInfo.FieldsInfo.Count == 0)
                return null;

            IFieldsEdit fields=new FieldsClass();
            foreach (FieldInfo fInfo in tInfo.FieldsInfo)
            {
                fields.AddField(CreateField(fInfo));
            }
            return fields;
        }
Example #27
0
        public void Create()
        {
            var tableInfo = new TableInfo(SystemSchema.ViewTableName);
            tableInfo.AddColumn("schema", PrimitiveTypes.String());
            tableInfo.AddColumn("name", PrimitiveTypes.String());
            tableInfo.AddColumn("query", PrimitiveTypes.String());
            tableInfo.AddColumn("plan", PrimitiveTypes.Binary());

            // TODO: Columns...

            Transaction.CreateTable(tableInfo);
        }
Example #28
0
 public void Create()
 {
     var tableInfo = new TableInfo(SystemSchema.TriggerTableName);
     tableInfo.AddColumn("schema", PrimitiveTypes.String());
     tableInfo.AddColumn("name", PrimitiveTypes.String());
     tableInfo.AddColumn("type", PrimitiveTypes.Integer());
     tableInfo.AddColumn("on_object", PrimitiveTypes.String());
     tableInfo.AddColumn("action", PrimitiveTypes.Integer());
     tableInfo.AddColumn("args", PrimitiveTypes.Binary());
     tableInfo.AddColumn("procedure_name", PrimitiveTypes.String());
     transaction.CreateTable(tableInfo);
 }
Example #29
0
        private static TableInfo CreateTableInfo(string schema, string name)
        {
            var tableInfo = new TableInfo(new ObjectName(new ObjectName(schema), name));

            tableInfo.AddColumn("type", PrimitiveTypes.Numeric());
            tableInfo.AddColumn("on_object", PrimitiveTypes.String());
            tableInfo.AddColumn("routine_name", PrimitiveTypes.String());
            tableInfo.AddColumn("param_args", PrimitiveTypes.String());
            tableInfo.AddColumn("owner", PrimitiveTypes.String());

            return tableInfo.AsReadOnly();
        }
Example #30
0
        public void setupConfig( IDatabase db )
        {
            // We want to find the impexporter config file.
            string nunitPath = TestContext.CurrentContext.WorkDirectory;
            string configPath = Path.Combine( nunitPath, "..", "..", "..", "config.xml" );
            _cfg = XmlPersistence.Load<ImpExporterConfig>( configPath );

            // Create the database itself.
            _db = db;

            _ti = new TableInfo();
        }