public static void BuildChildNodes(ITreeBuilder builder, TableSchema node)
        {
            if (node.Provider.SupportsSchemaType (typeof (ColumnSchema)))
                builder.AddChild (new ColumnsNode (node.Provider, node));

            if (node.Provider.SupportsSchemaType (typeof (RuleSchema)))
                builder.AddChild (new RulesNode (node.Provider));

            if (node.Provider.SupportsSchemaType (typeof (ConstraintSchema)))
                builder.AddChild (new ConstraintsNode (node.Provider, node));

            if (node.Provider.SupportsSchemaType (typeof (TriggerSchema)))
                builder.AddChild (new TriggersNode (node.Provider));
        }
        public static void ListTableColumns(TableSchema table)
        {
            ColumnSchema[] columns = table.Columns;

            for (int c = 0; c < columns.Length; c++) {
                ColumnSchema column = columns[c];
                Console.WriteLine("Column{0}: ", c);
                Console.WriteLine("  Name: {0}", column.Name);
                Console.WriteLine("  DataTypeName: {0}", column.DataTypeName);
                Console.WriteLine("  Length: {0}", column.Length);
                //Console.WriteLine("  Precision: {0}", column.Precision);
                //Console.WriteLine("  Scale: {0}", column.Scale);
                //Console.WriteLine("  NotNull: {0}", column.NotNull);
                Console.WriteLine("");
            }
        }
 public override ColumnSchema[] GetTableColumns(TableSchema table)
 {
     throw new NotImplementedException ();
 }
        /// <summary>
        /// Get a list of tables in the system.
        /// </summary>
        public override TableSchema[] GetTables()
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();

            SybaseCommand command = new SybaseCommand();
            command.Connection = connection;
            command.CommandText =
                "SELECT su.name AS owner, so.name as table_name, so.id as table_id, " +
                " so.crdate as created_date, so.type as table_type " +
                "FROM dbo.sysobjects so, dbo.sysusers su " +
                "WHERE type IN ('S','U') " +
                "AND su.uid = so.uid " +
                "ORDER BY 1, 2";
            SybaseDataReader r = command.ExecuteReader();

            while (r.Read()) {
                TableSchema table = new TableSchema();
                table.Provider = this;
                table.Name = r.GetString(1);

                table.IsSystemTable = r.GetString(4) == "S" ? true : false;

                table.SchemaName = r.GetString(0);
                table.OwnerName = r.GetString(0);
                table.Comment = "";

                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();
                collection.Add (table);
            }
            r.Close ();
            r = null;
            command.Dispose ();
            command = null;

            return (TableSchema[]) collection.ToArray (typeof (TableSchema));
        }
        /// <summary>
        /// Get a list of tables in the system.
        /// </summary>
        public override TableSchema[] GetTables()
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();

            DataTable dataTable = connection.GetSchema ("Tables", new string[] {null, null, null, "TABLE"});

            for (int r = 0; r < dataTable.Rows.Count; r++) {
                DataRow row = dataTable.Rows[r];
                string tableName = row["TABLE_NAME"].ToString();

                TableSchema table = new TableSchema();
                table.Provider = this;
                table.Name = tableName;
                table.IsSystemTable = false; // TODO

                table.SchemaName = String.Empty;
                table.OwnerName = String.Empty;
                table.Comment = String.Empty;

                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();
                collection.Add (table);

            }

            return (TableSchema[]) collection.ToArray (typeof (TableSchema));
        }
        public override TableSchema[] GetTables()
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();

            using (MySqlCommand command = new MySqlCommand ()) {
                command.Connection = Connection;
                command.CommandText =
                    "SHOW TABLES;";
                MySqlDataReader r = command.ExecuteReader ();

                while (r.Read ()) {
                    TableSchema table = new TableSchema ();
                    table.Provider = this;

                    table.Name = r.GetString (0);

                    collection.Add (table);
                }

                r.Close ();
            }

            return (TableSchema[]) collection.ToArray (typeof (TableSchema));
        }
        public override ColumnSchema[] GetTableColumns(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();

            using (MySqlCommand command = new MySqlCommand ()) {
                command.Connection = Connection;

                // XXX: Use String.Format cause mysql parameters suck assmar.
                command.CommandText =
                    String.Format ("DESCRIBE {0}", table.Name);
                MySqlDataReader r = command.ExecuteReader ();

                while (r.Read ()) {
                    ColumnSchema column = new ColumnSchema ();
                    column.Provider = this;

                    column.Name = r.GetString (0);
                    column.DataTypeName = r.GetString (1);
                    column.NotNull = r.IsDBNull (2);
                    column.Default = r.GetString (4);
                    column.Options["extra"] = r.GetString (5);

                    collection.Add (column);
                }

                r.Close ();
            }

            return (ColumnSchema[]) collection.ToArray (typeof (ColumnSchema));
        }
 private void OnTableAdd(ITreeBuilder builder, TableSchema schema)
 {
     if (((bool)builder.Options["ShowSystemObjects"]) == true || schema.IsSystemTable == false)
         builder.AddChild (schema);
     builder.Expanded = true;
 }
        /// <summary>
        /// Get columns for a table.
        /// </summary>
        public override ColumnSchema[] GetTableColumns(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList();

            NpgsqlCommand command = new NpgsqlCommand();
            command.Connection = connection;
            command.CommandText = "SELECT a.attname, a.attnotnull, a.attlen, "
                + "typ.typname, adef.adsrc "
                + "FROM "
                + "  pg_catalog.pg_attribute a LEFT JOIN "
                + "  pg_catalog.pg_attrdef adef "
                + "  ON a.attrelid=adef.adrelid "
                + "  AND a.attnum=adef.adnum "
                + "  LEFT JOIN pg_catalog.pg_type t ON a.atttypid=t.oid, "
                + "  pg_catalog.pg_type typ "
                + "WHERE "
                + "  a.attrelid = (SELECT oid FROM pg_catalog.pg_class "
                + "  WHERE relname='" + table.Name + "') "
                + "AND a.attnum > 0 AND NOT a.attisdropped "
                + "AND a.atttypid = typ.oid "
                + "ORDER BY a.attnum;";
            NpgsqlDataReader r = command.ExecuteReader();

            while (r.Read()) {
                ColumnSchema column = new ColumnSchema();

                try { column.Name = r.GetString(0); } catch {}
                column.Provider = this;
                try { column.DataTypeName = r.GetString(3); } catch {}
                try { column.Default = r.GetString(4); } catch {}
                column.Comment = "";
                column.OwnerName = "";
                column.SchemaName = table.SchemaName;
                try { column.NotNull = r.GetBoolean(1); } catch {}
                try { column.Length = r.GetInt32(2); } catch {}

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0} {1}{2}",
                    column.Name,
                    column.DataTypeName,
                    (column.Length > 0) ? ("(" + column.Length + ")") : "");
                sb.AppendFormat(" {0}", column.NotNull ? "NOT NULL" : "NULL");
                if (column.Default.Length > 0)
                    sb.AppendFormat(" DEFAULT {0}", column.Default);
                column.Definition = sb.ToString();

                collection.Add(column);
            }

            r.Close ();

            return (ColumnSchema[]) collection.ToArray(typeof(ColumnSchema));
        }
 public virtual ConstraintSchema[] GetTableConstraints(TableSchema schema)
 {
     throw new NotImplementedException ();
 }
 public virtual void GetTableConstraints(SQLCallback Callback, TableSchema schema)
 {
     Thread eThread = null;
     lock (ThreadSync) {
         ThreadedSQLCallback = Callback;
         ThreadedTableSchema = schema;
         eThread = new Thread (new ThreadStart (GetTableConstraintsThreadStart));
         eThread.Start ();
     }
 }
 public virtual ColumnSchema[] GetTableColumns(TableSchema schema)
 {
     throw new NotImplementedException ();
 }
        /// <summary>
        /// Get a list of tables in the system.
        /// </summary>
        public override TableSchema[] GetTables()
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection.");

            ArrayList collection = new ArrayList();

            OracleCommand command = new OracleCommand();
            command.Connection = connection;
            command.CommandText =
                "SELECT OWNER, TABLE_NAME, TABLESPACE_NAME " +
                "FROM ALL_TABLES " +
                "ORDER BY OWNER, TABLE_NAME";
            OracleDataReader r = command.ExecuteReader();

            while (r.Read()) {
                TableSchema table = new TableSchema();
                table.Provider = this;
                table.OwnerName = r.GetValue(0).ToString();
                table.SchemaName = r.GetValue(0).ToString();
                table.Name = r.GetString(1).ToString();
                table.IsSystemTable = IsSystem(table.OwnerName);
                table.TableSpaceName = r.GetValue(2).ToString();

                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.AppendFormat ("\n) COMMENT '{0}';", table.Comment);
                table.Definition = "";
                collection.Add (table);
            }

            return (TableSchema[]) collection.ToArray(typeof(TableSchema));
        }
        /// <summary>
        /// Get a collection of constraints within a a table.
        /// </summary>
        public override ConstraintSchema[] GetTableConstraints(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection.");

            ArrayList collection = new ArrayList ();

            OracleCommand command = new OracleCommand ();
            command.Connection = connection;
            command.CommandText =
                "SELECT k.owner, k.table_name, k.constraint_name, " +
                "       k.constraint_type, k.status, k.validated " +
                "FROM all_constraints k " +
                "WHERE k.owner = '" + table.OwnerName + "' " +
                "AND k.table_name = '" + table.Name + "' " +
                "and k.constraint_type = 'P'";
            OracleDataReader r = command.ExecuteReader ();

            while (r.Read ()) {
                ConstraintSchema constraint = null;
                switch (r.GetString(4)) {
                    case "P":
                    default:
                        constraint = new PrimaryKeyConstraintSchema();
                        break;
                }

                constraint.Name = r.GetString (3);
                constraint.Definition = "";

                collection.Add (constraint);
            }

            return (ConstraintSchema[]) collection.ToArray (typeof(ConstraintSchema));
        }
        /// <summary>
        /// Get columns for a table.
        /// </summary>
        public override ColumnSchema[] GetTableColumns(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection.");

            ArrayList collection = new ArrayList();

            OracleCommand command = new OracleCommand();
            command.Connection = connection;
            command.CommandText =
                "SELECT OWNER, TABLE_NAME, COLUMN_NAME, " +
                "       DATA_TYPE, DATA_LENGTH, DATA_PRECISION, DATA_SCALE, " +
                "       NULLABLE, COLUMN_ID, DEFAULT_LENGTH, DATA_DEFAULT " +
                "FROM ALL_TAB_COLUMNS " +
                "WHERE OWNER = '" + table.OwnerName + "' " +
                "AND TABLE_NAME = '" + table.Name + "' " +
                "ORDER BY OWNER, TABLE_NAME, COLUMN_ID";
            OracleDataReader r = command.ExecuteReader();

            while (r.Read()) {
                ColumnSchema column = new ColumnSchema();

                try { column.Name = r.GetValue(2).ToString(); } catch {}
                column.Provider = this;
                try { column.DataTypeName = r.GetValue(3).ToString(); } catch {}
                column.Default = "";
                column.Comment = "";
                column.OwnerName = table.OwnerName;
                column.SchemaName = table.OwnerName;

                try { column.NotNull = r.GetValue(7).ToString() == "Y" ? true : false; } catch {}

                try { column.Length = GetInt(r, 4); } catch {}
                try { column.Precision = GetInt(r, 5); } catch {}
                try { column.Scale = GetInt(r, 6); } catch {}

                try { column.ColumnID = GetInt(r, 8); } catch {}

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0} {1}{2}",
                    column.Name,
                    column.DataTypeName,
                    (column.Length > 0) ? ("(" + column.Length + ")") : "");
                sb.AppendFormat(" {0}", column.NotNull ? "NOT NULL" : "NULL");
                //if (column.Default.Length > 0)
                //	sb.AppendFormat(" DEFAULT {0}", column.Default);
                column.Definition = sb.ToString();

                collection.Add(column);
            }

            return (ColumnSchema[]) collection.ToArray(typeof(ColumnSchema));
        }
 public override ConstraintSchema[] GetTableConstraints(TableSchema table)
 {
     throw new NotImplementedException ();
 }
 public ConstraintsNode(DbProviderBase provider, TableSchema table)
 {
     Provider = provider;
     Table = table;
 }
        /// <summary>
        /// Get a collection of constraints within a a table.
        /// </summary>
        public override ConstraintSchema[] GetTableConstraints(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();

            NpgsqlCommand command = new NpgsqlCommand ();
            command.Connection = connection;
            command.CommandText = String.Format (
                "SELECT "
                + "pc.conname, "
                + "pg_catalog.pg_get_constraintdef(pc.oid, true) AS consrc, "
                + "pc.contype, "
                + "CASE WHEN pc.contype='u' OR pc.contype='p' THEN ( "
                + "	SELECT "
                + "		indisclustered "
                + "	FROM "
                + "		pg_catalog.pg_depend pd, "
                + "		pg_catalog.pg_class pl, "
                + "		pg_catalog.pg_index pi "
                + "	WHERE "
                + "		pd.refclassid=pc.tableoid "
                + "		AND pd.refobjid=pc.oid "
                + "		AND pd.objid=pl.oid "
                + "		AND pl.oid=pi.indexrelid "
                + ") ELSE "
                + "	NULL "
                + "END AS indisclustered "
                + "FROM "
                + "pg_catalog.pg_constraint pc "
                + "WHERE "
                + "pc.conrelid = (SELECT oid FROM pg_catalog.pg_class WHERE relname='{0}' "
                + "	AND relnamespace = (SELECT oid FROM pg_catalog.pg_namespace "
                + "	WHERE nspname='{1}')) "
                + "ORDER BY "
                + "1;", table.Name, table.SchemaName);
            NpgsqlDataReader r = command.ExecuteReader ();

            while (r.Read ()) {
                ConstraintSchema constraint = null;

                // XXX: Add support for Check constraints.
                switch (r.GetString(2)) {
                    case "f":
                        string match = @".*REFERENCES (.+)\(.*\).*";
                        constraint = new ForeignKeyConstraintSchema ();
                        if (Regex.IsMatch (r.GetString (1), match))
                            (constraint as ForeignKeyConstraintSchema).ReferenceTableName
                                = Regex.Match (r.GetString (1), match).Groups[0].Captures[0].Value;
                        break;
                    case "u":
                        constraint = new UniqueConstraintSchema ();
                        break;
                    case "p":
                    default:
                        constraint = new PrimaryKeyConstraintSchema ();
                        break;
                }

                constraint.Name = r.GetString (0);
                constraint.Definition = r.GetString (1);

                collection.Add (constraint);
            }

            r.Close ();

            return (ConstraintSchema[]) collection.ToArray (typeof(ConstraintSchema));
        }
        /// <summary>
        /// Get a collection of constraints within a a table.
        /// </summary>
        public override ConstraintSchema[] GetTableConstraints(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();
            // TODO:

            return (ConstraintSchema[]) collection.ToArray (typeof(ConstraintSchema));
        }
        /// <summary>
        /// Get a list of tables in the system.
        /// </summary>
        public override TableSchema[] GetTables()
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();

            NpgsqlCommand command = new NpgsqlCommand();
            command.Connection = connection;
            command.CommandText =
                "SELECT c.relname, n.nspname, u.usename, d.description "
                + "FROM pg_class c "
                + " LEFT JOIN pg_description d ON c.oid = d.objoid, "
                + "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;";
            NpgsqlDataReader r = command.ExecuteReader();

            while (r.Read()) {
                TableSchema table = new TableSchema();
                table.Provider = this;
                table.Name = r.GetString(0);

                if (table.Name.Substring(0, 3) == "pg_" ||
                    table.Name.Substring(0, 4) == "sql_")
                {
                    table.IsSystemTable = true;
                }

                try { table.SchemaName = r.GetString(1); } catch {}
                try { table.OwnerName = r.GetString(2); } catch {}
                try { table.Comment = r.GetString(3); } catch {}

                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();
                collection.Add (table);
            }

            r.Close ();

            return (TableSchema[]) collection.ToArray (typeof (TableSchema));
        }
        public override ConstraintSchema[] GetTableConstraints(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList ();

            using (MySqlCommand command = new MySqlCommand ()) {
                command.Connection = Connection;
                command.CommandText =
                    "";
                MySqlDataReader r = command.ExecuteReader ();

                while (r.Read ()) {
                    ConstraintSchema constraint = new ConstraintSchema ();
                    constraint.Provider = this;

                    // TODO: Implement

                    collection.Add (constraint);
                }

                r.Close ();
            }

            return (ConstraintSchema[]) collection.ToArray (
                typeof (ConstraintSchema));
        }
        /// <summary>
        /// Get columns for a table.
        /// </summary>
        public override ColumnSchema[] GetTableColumns(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList();
            SybaseConnection con2 = (SybaseConnection) (((ICloneable) connection).Clone ());
            if (con2.State == ConnectionState.Closed)
                con2.Open();
            SybaseCommand command = con2.CreateCommand ();

            command.CommandText =
                "select su.name as owner, so.name as table_name, sc.name as column_name,  " +
                    " st.name as date_type, sc.length as column_length,  " +
                    " sc.prec as data_preceision, sc.scale as data_scale, " +
                    " 0 as isnullable, sc.colid as column_id " +
                    "from dbo.syscolumns sc, dbo.sysobjects so, " +
                    "     dbo.systypes st, dbo.sysusers su " +
                    "where sc.id = so.id " +
                    "and so.type in ('U','S') " +
                    "and so.name = '" + table.Name + "' " +
                    "and su.name = '" + table.OwnerName + "' " +
                    "and su.uid = so.uid " +
                    "and sc.usertype = st.usertype " +
                    "order by sc.colid";

            SybaseDataReader r = command.ExecuteReader();

            while (r.Read()) {
                ColumnSchema column = new ColumnSchema();

                try { column.Name = r.GetString(2); } catch {}
                column.Provider = this;
                try { column.DataTypeName = r.GetString(3); } catch {}
                try { column.Default = ""; } catch {}
                column.Comment = "";
                column.OwnerName = table.OwnerName;
                column.SchemaName = table.OwnerName;
                try { column.NotNull = r.GetValue(7).ToString() == "0" ? true : false;  } catch {}
                try { column.Length = r.GetInt32(4); } catch {}
                //try { column.Precision = GetInt(r, 5)); } catch {}
                //try { column.Scale = GetIn(r, 6); } catch {}

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0} {1}{2}",
                    column.Name,
                    column.DataTypeName,
                    (column.Length > 0) ? ("(" + column.Length + ")") : "");
                sb.AppendFormat(" {0}", column.NotNull ? "NOT NULL" : "NULL");
                //if (column.Default.Length > 0)
                //	sb.AppendFormat(" DEFAULT {0}", column.Default);
                column.Definition = sb.ToString();

                collection.Add(column);
            }
            r.Close ();
            r = null;
            command.Dispose ();
            command = null;
            con2.Close ();
            con2 = null;

            return (ColumnSchema[]) collection.ToArray(typeof(ColumnSchema));
        }
        /// <summary>
        /// Get a collection of constraints within a a table.
        /// </summary>
        public override ConstraintSchema[] GetTableConstraints(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            //			ArrayList collection = new ArrayList ();
            //
            //			SybaseConnection con2 = (SybaseConnection) (((ICloneable) connection).Clone ());
            //			con2.Open();
            //			SybaseCommand command = con2.CreateCommand ();

            // TODO: get constraints
            return new ConstraintSchema[0];
        }
        /// <summary>
        /// Get columns for a table.
        /// </summary>
        public override ColumnSchema[] GetTableColumns(TableSchema table)
        {
            if (IsOpen == false && Open () == false)
                throw new InvalidOperationException ("Invalid connection");

            ArrayList collection = new ArrayList();

            DataTable table2 = connection.GetSchema ("Columns", new string[] {null, null, table.Name, null});
            for (int r = 0; r < table2.Rows.Count; r++) {
                DataRow row2 = table2.Rows[r];

                string columnName =	row2["COLUMN_NAME"].ToString();
                string dataType = row2["COLUMN_DATA_TYPE"].ToString();

                int columnSize = 0;
                if (row2["COLUMN_SIZE"] != DBNull.Value)
                    columnSize = (int) row2["COLUMN_SIZE"];

                int precision = 0;
                if (row2["NUMERIC_PRECISION"] != DBNull.Value)
                    precision = (int) row2["NUMERIC_PRECISION"];

                int scale = 0;
                if (row2["NUMERIC_SCALE"] != DBNull.Value)
                    scale = (int) row2["NUMERIC_SCALE"];

                //bool isNullable = false; // FIXME: is nullable
                //short n = 0;
                //if (row2["IS_NULLABLE"] != DBNull.Value)
                //	n = (short) row2["IS_NULLABLE"];
                //
                //if (n == 1)
                //	isNullable = true;

                //int pos = 0; // FIXME: ordinal position
                //if (row2["ORDINAL_POSITION"] != DBNull.Value)
                //	pos = (int) row2["ORDINAL_POSITION"];

                ColumnSchema column = new ColumnSchema();

                column.Name = columnName;
                column.Provider = this;
                column.DataTypeName = dataType;
                column.Default = "";
                column.Comment = "";
                column.OwnerName = "";
                column.SchemaName = table.SchemaName;
                column.NotNull = false; // TODO
                column.Length = columnSize;
                column.Precision = precision;
                column.Scale = scale;

                StringBuilder sb = new StringBuilder();
                sb.AppendFormat("{0} {1}{2}",
                    column.Name,
                    column.DataTypeName,
                    (column.Length > 0) ? ("(" + column.Length + ")") : "");
                sb.AppendFormat(" {0}", column.NotNull ? "NOT NULL" : "NULL");
                if (column.Default.Length > 0)
                    sb.AppendFormat(" DEFAULT {0}", column.Default);
                column.Definition = sb.ToString();

                collection.Add(column);
            }

            return (ColumnSchema[]) collection.ToArray(typeof(ColumnSchema));
        }