[Mono-list] Database Schema

Kamil Skalski nazgul@omega.pl
Fri, 7 May 2004 10:12:37 +0200


Thursday 06 May 2004 17:08, Pedro Santos wrote:
> Hello.
>
> What's the best way to get the Database schema? The only way I see is to
> perform a query to a DataSet and get get the schema from the DataSet. Is
> there any other way?

I'm not sure this is what you want, but I use following procedures to get 
Schema of some table in database (it is used later to validate sql queries 
and types of parameters passed to those queries at compile time)

  def dbcmd = NpgsqlCommand ("SELECT * FROM employee", dbcon);
     def reader = dbcmd.ExecuteReader(System.Data.CommandBehavior.SchemaOnly);
       Console.WriteLine("query executed...");
       def _S = reader.GetSchemaTable ();
       foreach(myRow : System.Data.DataRow in _S.Rows){
         Console.WriteLine (myRow["ColumnName"].ToString () + " : " +
                            myRow["DataType"].ToString ());
       };

This code prints columns of table "employee" together with their types.

Kamil