Ejemplo n.º 1
0
        public override TableSchemaCollection GetTables()
        {
            TableSchemaCollection tables = new TableSchemaCollection();

            IPooledDbConnection conn    = connectionPool.Request();
            IDbCommand          command = conn.CreateCommand(
                "SELECT name, sql FROM sqlite_master WHERE type = 'table'"
                );

            try {
                using (command) {
                    using (IDataReader r = command.ExecuteReader()) {
                        while (r.Read())
                        {
                            TableSchema table = new TableSchema(this);

                            table.SchemaName    = "main";
                            table.Name          = r.GetString(0);
                            table.IsSystemTable = table.Name.StartsWith("sqlite_");
                            table.Definition    = r.GetString(1);

                            tables.Add(table);
                        }
                        r.Close();
                    }
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(tables);
        }
        public virtual TableSchemaCollection GetTables()
        {
            TableSchemaCollection collection = new TableSchemaCollection();

            IPooledDbConnection conn = connectionPool.Request();

            try {
                //restrictions: database, schema, table, table type
                DataTable dt = conn.GetSchema(tablesCollectionString, null, connectionPool.ConnectionContext.ConnectionSettings.Database);
                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    DataRow row = dt.Rows[r];
                    collection.Add(GetTable(row));
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(collection);
        }
Ejemplo n.º 3
0
        public virtual TableSchemaCollection GetTables()
        {
            TableSchemaCollection collection = new TableSchemaCollection();

            IPooledDbConnection conn = connectionPool.Request();

            try {
                //restrictions: database, schema, table, table type
                DataTable dt = conn.GetSchema(tablesCollectionString, null, connectionPool.ConnectionContext.ConnectionSettings.Database);
                for (int r = 0; r < dt.Rows.Count; r++)
                {
                    DataRow row = dt.Rows[r];
                    collection.Add(GetTable(row));
                }
            } catch (Exception e) {
                // Don't raise error, if the triggers doesn't exists return an empty collection
            }
            conn.Release();

            return(collection);
        }
Ejemplo n.º 4
0
        public override TableSchemaCollection GetTables()
        {
            TableSchemaCollection tables = new TableSchemaCollection();

            IPooledDbConnection conn    = connectionPool.Request();
            IDbCommand          command = conn.CreateCommand(
                "SELECT su.name AS owner, so.name as table_name, so.id as table_id, " +
                " so.crdate as created_date, so.xtype as table_type " +
                " FROM dbo.sysobjects so, dbo.sysusers su " +
                "WHERE xtype IN ('S','U') " +
                "AND su.uid = so.uid " +
                "ORDER BY 1, 2"
                );

            try {
                using (command) {
                    using (IDataReader r = command.ExecuteReader()) {
                        while (r.Read())
                        {
                            TableSchema table = new TableSchema(this);

                            table.Name          = r.GetString(1);
                            table.IsSystemTable = r.GetString(4) == "S" ? true : false;
                            table.OwnerName     = r.GetString(0);
                            table.Definition    = GetTableDefinition(table);

                            tables.Add(table);
                        }
                        r.Close();
                    }
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(tables);
        }
 public TableSchemaCollection(TableSchemaCollection collection)
     : base(collection, true)
 {
 }
        public override TableSchemaCollection GetTables()
        {
            TableSchemaCollection tables = new TableSchemaCollection();

            IPooledDbConnection conn    = connectionPool.Request();
            IDbCommand          command = conn.CreateCommand(
                "SELECT DISTINCT c.relname, n.nspname, u.usename "
                + "FROM pg_class c, pg_namespace n, pg_user u "
                + "WHERE c.relnamespace = n.oid "
                + "AND c.relowner = u.usesysid "
                + "AND c.relkind='r' AND NOT EXISTS "
                + "   (SELECT 1 FROM pg_rewrite r "
                + "      WHERE r.ev_class = c.oid AND r.ev_type = '1') "
                + "ORDER BY relname;"
                );

            try {
                using (command) {
                    using (IDataReader r = command.ExecuteReader()) {
                        while (r.Read())
                        {
                            TableSchema table = new TableSchema(this);

                            table.Name          = r.GetString(0);
                            table.IsSystemTable = table.Name.StartsWith("pg_") || table.Name.StartsWith("sql_");
                            table.SchemaName    = r.GetString(1);
                            table.OwnerName     = r.GetString(2);

//							StringBuilder sb = new StringBuilder();
//							sb.AppendFormat ("-- Table: {0}\n", table.Name);
//							sb.AppendFormat ("-- DROP TABLE {0};\n\n", table.Name);
//							sb.AppendFormat ("CREATE TABLE {0} (\n", table.Name);
//
//							ColumnSchema[] columns = table.Columns;
//							string[] parts = new string[columns.Length];
//							for (int i = 0; i < parts.Length; i++) {
//								parts[i] = "\t" + columns[i].Definition;
//							}
//							sb.Append (String.Join (",\n", parts));
//
//							ConstraintSchema[] cons = table.Constraints;
//							parts = new string[cons.Length];
//							if (cons.Length > 0)
//								sb.Append (",\n");
//							for (int i = 0; i < parts.Length; i++) {
//								parts[i] = "\t" + cons[i].Definition;
//							}
//							sb.Append (String.Join (",\n", parts));
//
//							sb.Append ("\n);\n");
//							sb.AppendFormat ("COMMENT ON TABLE {0} IS '{1}';", table.Name, table.Comment);
//							table.Definition = sb.ToString();

                            tables.Add(table);
                        }
                        r.Close();
                    }
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(tables);
        }
        // see: http://dev.mysql.com/doc/refman/5.1/en/tables-table.html
        // // see: http://dev.mysql.com/doc/refman/5.1/en/show-create-table.html
        public override TableSchemaCollection GetTables()
        {
            TableSchemaCollection tables = new TableSchemaCollection();

            IPooledDbConnection conn    = connectionPool.Request();
            IDbCommand          command = conn.CreateCommand("SHOW TABLES;");

            try {
                using (command) {
                    if (GetMainVersion(command) >= 5)
                    {
                        //in mysql 5.x we can use an sql query to provide the comment
                        command.CommandText = "SELECT TABLE_NAME, TABLE_SCHEMA, TABLE_TYPE, TABLE_COMMENT FROM `information_schema`.`TABLES` "
                                              + "WHERE TABLE_TYPE='BASE TABLE' AND TABLE_SCHEMA='"
                                              + command.Connection.Database
                                              + "' ORDER BY TABLE_NAME;";
                        using (IDataReader r = command.ExecuteReader()) {
                            while (r.Read())
                            {
                                TableSchema table = new TableSchema(this);

                                table.Name       = r.GetString(0);
                                table.SchemaName = r.GetString(1);
                                table.Comment    = r.IsDBNull(3) ? null : r.GetString(3);

                                IPooledDbConnection conn2    = connectionPool.Request();
                                IDbCommand          command2 = conn2.CreateCommand("SHOW CREATE TABLE `" + table.Name + "`;");
                                using (IDataReader r2 = command2.ExecuteReader()) {
                                    r2.Read();
                                    table.Definition = r2.GetString(1);
                                }
                                conn2.Release();

                                tables.Add(table);
                            }
                            r.Close();
                        }
                    }
                    else
                    {
                        //use the default command for mysql 4.x and 3.23
                        using (IDataReader r = command.ExecuteReader()) {
                            while (r.Read())
                            {
                                TableSchema table = new TableSchema(this);

                                table.Name       = r.GetString(0);
                                table.SchemaName = command.Connection.Database;

                                IPooledDbConnection conn2    = connectionPool.Request();
                                IDbCommand          command2 = conn2.CreateCommand("SHOW CREATE TABLE `" + table.Name + "`;");
                                using (IDataReader r2 = command2.ExecuteReader()) {
                                    r2.Read();
                                    table.Definition = r2.GetString(1);
                                }
                                conn2.Release();

                                tables.Add(table);
                            }
                            r.Close();
                        }
                    }
                }
            } catch (Exception e) {
                QueryService.RaiseException(e);
            }
            conn.Release();

            return(tables);
        }