diff options
18 files changed, 427 insertions, 161 deletions
diff --git a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommand.cs b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommand.cs index d287da27c5e..49183916f8d 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommand.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlCommand.cs @@ -240,7 +240,7 @@ namespace System.Data.SqlClient { int oid; types = new string[nFields]; - + for(nCol = 0; nCol < nFields; nCol++) { DbType dbType; diff --git a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs index dc6ee48a677..ffaf076ca66 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs @@ -19,6 +19,10 @@ // Gonzalo Paniagua Javier <gonzalo@gnome-db.org> // +// *** uncomment #define to get debug messages, comment for production *** +//#define DEBUG_SqlDataReader + + using System; using System.Collections; using System.ComponentModel; @@ -39,9 +43,13 @@ namespace System.Data.SqlClient { private SqlCommand cmd; private DataTable table; - private object[] fields; + // columns in a row + private object[] fields; // data value in a .NET type private string[] types; // PostgreSQL Type - private bool[] isNull; + private bool[] isNull; // is NULL? + private int[] actualLength; // ActualLength of data + private DbType[] dbTypes; // DB data type + // actucalLength = -1 is variable-length private bool open = false; IntPtr pgResult; // PGresult @@ -91,40 +99,60 @@ namespace System.Data.SqlClient { [MonoTODO] public bool Read() { - string value; - fields = new object[cols]; // re-init row - DbType dbType; - + string dataValue; + int c = 0; + + //Console.WriteLine("if current row: " + currentRow + " rows: " + rows); if(currentRow < rows - 1) { + + //Console.WriteLine("currentRow++: "); currentRow++; - int c; + + //Console.WriteLine("re-init row --- cols: " + cols); + + // re-init row + fields = new object[cols]; + //dbTypes = new DbType[cols]; + actualLength = new int[cols]; + isNull = new bool[cols]; + for(c = 0; c < cols; c++) { // get data value - value = PostgresLibrary. + dataValue = PostgresLibrary. PQgetvalue( pgResult, currentRow, c); - int columnIsNull; // is column NULL? - columnIsNull = PostgresLibrary. - PQgetisnull(pgResult, - currentRow, c); + //isNull[c] = PostgresLibrary. + // PQgetisnull(pgResult, + // currentRow, c); - int actualLength; // get Actual Length - actualLength = PostgresLibrary. + actualLength[c] = PostgresLibrary. PQgetlength(pgResult, currentRow, c); - + + DbType dbType; dbType = PostgresHelper. TypnameToSqlDbType(types[c]); - fields[c] = PostgresHelper. - ConvertDbTypeToSystem ( + if(dataValue == null) { + fields[c] = null; + isNull[c] = true; + } + else if(dataValue.Equals("")) { + fields[c] = null; + isNull[c] = true; + } + else { + isNull[c] = false; + fields[c] = PostgresHelper. + ConvertDbTypeToSystem ( dbType, - value); + dataValue); + } } return true; } @@ -162,12 +190,12 @@ namespace System.Data.SqlClient { [MonoTODO] public string GetDataTypeName(int i) { - throw new NotImplementedException (); + return types[i]; } [MonoTODO] public DateTime GetDateTime(int i) { - throw new NotImplementedException (); + return (DateTime) fields[i]; } [MonoTODO] @@ -182,7 +210,8 @@ namespace System.Data.SqlClient { [MonoTODO] public Type GetFieldType(int i) { - throw new NotImplementedException (); + + return table.Columns[i].DataType; } [MonoTODO] @@ -217,7 +246,27 @@ namespace System.Data.SqlClient { [MonoTODO] public int GetOrdinal(string name) { - throw new NotImplementedException (); + int i; + for(i = 0; i < cols; i ++) { + if(table.Columns[i].ColumnName.Equals(name)) { + return i; + } + + } + + for(i = 0; i < cols; i++) { + string ta; + string n; + + ta = table.Columns[i].ColumnName.ToUpper(); + n = name.ToUpper(); + + if(ta.Equals(n)) { + return i; + } + } + + throw new MissingFieldException("Missing field: " + name); } [MonoTODO] @@ -232,12 +281,14 @@ namespace System.Data.SqlClient { [MonoTODO] public int GetValues(object[] values) { - throw new NotImplementedException (); + + values = fields; + return fields.Length; } [MonoTODO] public bool IsDBNull(int i) { - throw new NotImplementedException (); + return isNull[i]; } [MonoTODO] diff --git a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PostgresLibrary.cs b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PostgresLibrary.cs index fb3284a9453..a45a3991ef7 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PostgresLibrary.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/Mono.Data.PostgreSqlClient/PostgresLibrary.cs @@ -15,7 +15,7 @@ // // *** uncomment #define to get debug messages, comment for production *** -// #define DEBUG_PostgresLibrary +//#define DEBUG_PostgresLibrary using System; using System.Data; @@ -243,27 +243,40 @@ namespace System.Data.SqlClient { // from PostgreSQL oid type // to .NET System.<type> - // TODO: need to handle a NULL for each type + // FIXME: need to handle a NULL for each type // maybe setting obj to System.DBNull.Value ? -#if DEBUG_PostgresLibrary - Console.WriteLine("ConvertDbTypeToSystem typ: " + - typ + " value: " + value); -#endif // DEBUG_PostgresLibrary +// +// if(value == null) { +//#if DEBUG_PostgresLibrary +// Console.WriteLine("column is NULL"); +//#endif // DEBUG_PostgresLibrary +// return null; +// } +// else if(value.Equals("")) { +//#if DEBUG_PostgresLibrary +// Console.WriteLine("column has a NULL"); +//#endif // DEBUG_PostgresLibrary +// +// return null; +// } +// +//#if DEBUG_PostgresLibrary +// Console.WriteLine("ConvertDbTypeToSystem typ: " + +// typ + " value: " + value); +//#endif // DEBUG_PostgresLibrary +// // Date, Time, and DateTime // are parsed based on ISO format - // "YYYY-MM-DD hh:mi:ss:ms" + // "YYYY-MM-DD hh:mi:ss.ms" switch(typ) { case DbType.String: obj = String.Copy(value); break; case DbType.Boolean: - if(value.Equals("t")) - obj = Boolean.Parse("true"); - else - obj = Boolean.Parse("false"); + obj = value.Equals("t"); break; case DbType.Int16:
obj = Int16.Parse(value);
diff --git a/mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommand.cs b/mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommand.cs index d287da27c5e..49183916f8d 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommand.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/PgSqlCommand.cs @@ -240,7 +240,7 @@ namespace System.Data.SqlClient { int oid; types = new string[nFields]; - + for(nCol = 0; nCol < nFields; nCol++) { DbType dbType; diff --git a/mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs b/mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs index dc6ee48a677..ffaf076ca66 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/PgSqlDataReader.cs @@ -19,6 +19,10 @@ // Gonzalo Paniagua Javier <gonzalo@gnome-db.org> // +// *** uncomment #define to get debug messages, comment for production *** +//#define DEBUG_SqlDataReader + + using System; using System.Collections; using System.ComponentModel; @@ -39,9 +43,13 @@ namespace System.Data.SqlClient { private SqlCommand cmd; private DataTable table; - private object[] fields; + // columns in a row + private object[] fields; // data value in a .NET type private string[] types; // PostgreSQL Type - private bool[] isNull; + private bool[] isNull; // is NULL? + private int[] actualLength; // ActualLength of data + private DbType[] dbTypes; // DB data type + // actucalLength = -1 is variable-length private bool open = false; IntPtr pgResult; // PGresult @@ -91,40 +99,60 @@ namespace System.Data.SqlClient { [MonoTODO] public bool Read() { - string value; - fields = new object[cols]; // re-init row - DbType dbType; - + string dataValue; + int c = 0; + + //Console.WriteLine("if current row: " + currentRow + " rows: " + rows); if(currentRow < rows - 1) { + + //Console.WriteLine("currentRow++: "); currentRow++; - int c; + + //Console.WriteLine("re-init row --- cols: " + cols); + + // re-init row + fields = new object[cols]; + //dbTypes = new DbType[cols]; + actualLength = new int[cols]; + isNull = new bool[cols]; + for(c = 0; c < cols; c++) { // get data value - value = PostgresLibrary. + dataValue = PostgresLibrary. PQgetvalue( pgResult, currentRow, c); - int columnIsNull; // is column NULL? - columnIsNull = PostgresLibrary. - PQgetisnull(pgResult, - currentRow, c); + //isNull[c] = PostgresLibrary. + // PQgetisnull(pgResult, + // currentRow, c); - int actualLength; // get Actual Length - actualLength = PostgresLibrary. + actualLength[c] = PostgresLibrary. PQgetlength(pgResult, currentRow, c); - + + DbType dbType; dbType = PostgresHelper. TypnameToSqlDbType(types[c]); - fields[c] = PostgresHelper. - ConvertDbTypeToSystem ( + if(dataValue == null) { + fields[c] = null; + isNull[c] = true; + } + else if(dataValue.Equals("")) { + fields[c] = null; + isNull[c] = true; + } + else { + isNull[c] = false; + fields[c] = PostgresHelper. + ConvertDbTypeToSystem ( dbType, - value); + dataValue); + } } return true; } @@ -162,12 +190,12 @@ namespace System.Data.SqlClient { [MonoTODO] public string GetDataTypeName(int i) { - throw new NotImplementedException (); + return types[i]; } [MonoTODO] public DateTime GetDateTime(int i) { - throw new NotImplementedException (); + return (DateTime) fields[i]; } [MonoTODO] @@ -182,7 +210,8 @@ namespace System.Data.SqlClient { [MonoTODO] public Type GetFieldType(int i) { - throw new NotImplementedException (); + + return table.Columns[i].DataType; } [MonoTODO] @@ -217,7 +246,27 @@ namespace System.Data.SqlClient { [MonoTODO] public int GetOrdinal(string name) { - throw new NotImplementedException (); + int i; + for(i = 0; i < cols; i ++) { + if(table.Columns[i].ColumnName.Equals(name)) { + return i; + } + + } + + for(i = 0; i < cols; i++) { + string ta; + string n; + + ta = table.Columns[i].ColumnName.ToUpper(); + n = name.ToUpper(); + + if(ta.Equals(n)) { + return i; + } + } + + throw new MissingFieldException("Missing field: " + name); } [MonoTODO] @@ -232,12 +281,14 @@ namespace System.Data.SqlClient { [MonoTODO] public int GetValues(object[] values) { - throw new NotImplementedException (); + + values = fields; + return fields.Length; } [MonoTODO] public bool IsDBNull(int i) { - throw new NotImplementedException (); + return isNull[i]; } [MonoTODO] diff --git a/mcs/class/Mono.Data.PostgreSqlClient/PostgresLibrary.cs b/mcs/class/Mono.Data.PostgreSqlClient/PostgresLibrary.cs index fb3284a9453..a45a3991ef7 100644 --- a/mcs/class/Mono.Data.PostgreSqlClient/PostgresLibrary.cs +++ b/mcs/class/Mono.Data.PostgreSqlClient/PostgresLibrary.cs @@ -15,7 +15,7 @@ // // *** uncomment #define to get debug messages, comment for production *** -// #define DEBUG_PostgresLibrary +//#define DEBUG_PostgresLibrary using System; using System.Data; @@ -243,27 +243,40 @@ namespace System.Data.SqlClient { // from PostgreSQL oid type // to .NET System.<type> - // TODO: need to handle a NULL for each type + // FIXME: need to handle a NULL for each type // maybe setting obj to System.DBNull.Value ? -#if DEBUG_PostgresLibrary - Console.WriteLine("ConvertDbTypeToSystem typ: " + - typ + " value: " + value); -#endif // DEBUG_PostgresLibrary +// +// if(value == null) { +//#if DEBUG_PostgresLibrary +// Console.WriteLine("column is NULL"); +//#endif // DEBUG_PostgresLibrary +// return null; +// } +// else if(value.Equals("")) { +//#if DEBUG_PostgresLibrary +// Console.WriteLine("column has a NULL"); +//#endif // DEBUG_PostgresLibrary +// +// return null; +// } +// +//#if DEBUG_PostgresLibrary +// Console.WriteLine("ConvertDbTypeToSystem typ: " + +// typ + " value: " + value); +//#endif // DEBUG_PostgresLibrary +// // Date, Time, and DateTime // are parsed based on ISO format - // "YYYY-MM-DD hh:mi:ss:ms" + // "YYYY-MM-DD hh:mi:ss.ms" switch(typ) { case DbType.String: obj = String.Copy(value); break; case DbType.Boolean: - if(value.Equals("t")) - obj = Boolean.Parse("true"); - else - obj = Boolean.Parse("false"); + obj = value.Equals("t"); break; case DbType.Int16:
obj = Int16.Parse(value);
diff --git a/mcs/class/System.Data/ChangeLog b/mcs/class/System.Data/ChangeLog index 8507c579181..bdebf288584 100644 --- a/mcs/class/System.Data/ChangeLog +++ b/mcs/class/System.Data/ChangeLog @@ -1,3 +1,25 @@ +2002-05-11 Daniel Morgan <danmorg@sc.rr.com> + + * System.Data.build: added copy of System.Data.dll to Test directory + for easy testing. Also, added clean for it too. + + * System.Data.SqlClient/PostgresLibrary.cs: changed setting of boolean + from PostgreSQL data type to .NET type. + + * System.Data.SqlClient/SqlDataReader.cs: beginnings + handling of a NULL value from the database + + * Test/PostgresTest.cs: added tests for NULL values retrieved + from the database + + * Test/ReadPostgresData.cs + * Test/TestExecuteScalar.cs + * Test/TestSqlDataReader.cs + * Test/TestSqlException.cs + * Test/TestSqlIsolationLevel.cs: updated tests to use databas user + "postgres". These tests may eventually be removed since they + are not flexible. + 2002-05-10 Rodrigo Moya <rodrigo@ximian.com> * System.Data.build: removed reference to non-existant diff --git a/mcs/class/System.Data/System.Data.SqlClient/PostgresLibrary.cs b/mcs/class/System.Data/System.Data.SqlClient/PostgresLibrary.cs index fb3284a9453..a45a3991ef7 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/PostgresLibrary.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/PostgresLibrary.cs @@ -15,7 +15,7 @@ // // *** uncomment #define to get debug messages, comment for production *** -// #define DEBUG_PostgresLibrary +//#define DEBUG_PostgresLibrary using System; using System.Data; @@ -243,27 +243,40 @@ namespace System.Data.SqlClient { // from PostgreSQL oid type // to .NET System.<type> - // TODO: need to handle a NULL for each type + // FIXME: need to handle a NULL for each type // maybe setting obj to System.DBNull.Value ? -#if DEBUG_PostgresLibrary - Console.WriteLine("ConvertDbTypeToSystem typ: " + - typ + " value: " + value); -#endif // DEBUG_PostgresLibrary +// +// if(value == null) { +//#if DEBUG_PostgresLibrary +// Console.WriteLine("column is NULL"); +//#endif // DEBUG_PostgresLibrary +// return null; +// } +// else if(value.Equals("")) { +//#if DEBUG_PostgresLibrary +// Console.WriteLine("column has a NULL"); +//#endif // DEBUG_PostgresLibrary +// +// return null; +// } +// +//#if DEBUG_PostgresLibrary +// Console.WriteLine("ConvertDbTypeToSystem typ: " + +// typ + " value: " + value); +//#endif // DEBUG_PostgresLibrary +// // Date, Time, and DateTime // are parsed based on ISO format - // "YYYY-MM-DD hh:mi:ss:ms" + // "YYYY-MM-DD hh:mi:ss.ms" switch(typ) { case DbType.String: obj = String.Copy(value); break; case DbType.Boolean: - if(value.Equals("t")) - obj = Boolean.Parse("true"); - else - obj = Boolean.Parse("false"); + obj = value.Equals("t"); break; case DbType.Int16:
obj = Int16.Parse(value);
diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs index d287da27c5e..49183916f8d 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlCommand.cs @@ -240,7 +240,7 @@ namespace System.Data.SqlClient { int oid; types = new string[nFields]; - + for(nCol = 0; nCol < nFields; nCol++) { DbType dbType; diff --git a/mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs b/mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs index dc6ee48a677..ffaf076ca66 100644 --- a/mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs +++ b/mcs/class/System.Data/System.Data.SqlClient/SqlDataReader.cs @@ -19,6 +19,10 @@ // Gonzalo Paniagua Javier <gonzalo@gnome-db.org> // +// *** uncomment #define to get debug messages, comment for production *** +//#define DEBUG_SqlDataReader + + using System; using System.Collections; using System.ComponentModel; @@ -39,9 +43,13 @@ namespace System.Data.SqlClient { private SqlCommand cmd; private DataTable table; - private object[] fields; + // columns in a row + private object[] fields; // data value in a .NET type private string[] types; // PostgreSQL Type - private bool[] isNull; + private bool[] isNull; // is NULL? + private int[] actualLength; // ActualLength of data + private DbType[] dbTypes; // DB data type + // actucalLength = -1 is variable-length private bool open = false; IntPtr pgResult; // PGresult @@ -91,40 +99,60 @@ namespace System.Data.SqlClient { [MonoTODO] public bool Read() { - string value; - fields = new object[cols]; // re-init row - DbType dbType; - + string dataValue; + int c = 0; + + //Console.WriteLine("if current row: " + currentRow + " rows: " + rows); if(currentRow < rows - 1) { + + //Console.WriteLine("currentRow++: "); currentRow++; - int c; + + //Console.WriteLine("re-init row --- cols: " + cols); + + // re-init row + fields = new object[cols]; + //dbTypes = new DbType[cols]; + actualLength = new int[cols]; + isNull = new bool[cols]; + for(c = 0; c < cols; c++) { // get data value - value = PostgresLibrary. + dataValue = PostgresLibrary. PQgetvalue( pgResult, currentRow, c); - int columnIsNull; // is column NULL? - columnIsNull = PostgresLibrary. - PQgetisnull(pgResult, - currentRow, c); + //isNull[c] = PostgresLibrary. + // PQgetisnull(pgResult, + // currentRow, c); - int actualLength; // get Actual Length - actualLength = PostgresLibrary. + actualLength[c] = PostgresLibrary. PQgetlength(pgResult, currentRow, c); - + + DbType dbType; dbType = PostgresHelper. TypnameToSqlDbType(types[c]); - fields[c] = PostgresHelper. - ConvertDbTypeToSystem ( + if(dataValue == null) { + fields[c] = null; + isNull[c] = true; + } + else if(dataValue.Equals("")) { + fields[c] = null; + isNull[c] = true; + } + else { + isNull[c] = false; + fields[c] = PostgresHelper. + ConvertDbTypeToSystem ( dbType, - value); + dataValue); + } } return true; } @@ -162,12 +190,12 @@ namespace System.Data.SqlClient { [MonoTODO] public string GetDataTypeName(int i) { - throw new NotImplementedException (); + return types[i]; } [MonoTODO] public DateTime GetDateTime(int i) { - throw new NotImplementedException (); + return (DateTime) fields[i]; } [MonoTODO] @@ -182,7 +210,8 @@ namespace System.Data.SqlClient { [MonoTODO] public Type GetFieldType(int i) { - throw new NotImplementedException (); + + return table.Columns[i].DataType; } [MonoTODO] @@ -217,7 +246,27 @@ namespace System.Data.SqlClient { [MonoTODO] public int GetOrdinal(string name) { - throw new NotImplementedException (); + int i; + for(i = 0; i < cols; i ++) { + if(table.Columns[i].ColumnName.Equals(name)) { + return i; + } + + } + + for(i = 0; i < cols; i++) { + string ta; + string n; + + ta = table.Columns[i].ColumnName.ToUpper(); + n = name.ToUpper(); + + if(ta.Equals(n)) { + return i; + } + } + + throw new MissingFieldException("Missing field: " + name); } [MonoTODO] @@ -232,12 +281,14 @@ namespace System.Data.SqlClient { [MonoTODO] public int GetValues(object[] values) { - throw new NotImplementedException (); + + values = fields; + return fields.Length; } [MonoTODO] public bool IsDBNull(int i) { - throw new NotImplementedException (); + return isNull[i]; } [MonoTODO] diff --git a/mcs/class/System.Data/System.Data.build b/mcs/class/System.Data/System.Data.build index 03d73c1cc59..f2e24951b38 100644 --- a/mcs/class/System.Data/System.Data.build +++ b/mcs/class/System.Data/System.Data.build @@ -13,9 +13,9 @@ <arg value="/nowarn:0169"/>
<arg value="/nowarn:0649"/>
<arg value="/unsafe"/>
- <arg value="/noconfig"/> - <arg value="/r:System.dll"/> - <arg value="/r:System.Xml.dll"/> + <arg value="/noconfig"/>
+ <arg value="/r:System.dll"/>
+ <arg value="/r:System.Xml.dll"/>
<sources>
<includes name="**/*.cs"/>
<excludes name="System.Data/DataTableRelationCollection.cs"/>
@@ -38,11 +38,14 @@ <includes name="../lib/System.Xml.dll"/>
</references>
</csc>
+ <copy file="../lib/System.Data.dll" tofile="Test/System.Data.dll"/>
</target>
<target name="test" depends="build">
<nant basedir="Test" target="test"/>
</target>
<target name="clean">
<delete file="../lib/System.Data.dll" failonerror="false"/>
+ <delete file="Test/System.Data.dll" failonerror="false"/>
+
</target>
</project>
diff --git a/mcs/class/System.Data/Test/PostgresTest.cs b/mcs/class/System.Data/Test/PostgresTest.cs index faa381e259f..f6fd3f1945a 100644 --- a/mcs/class/System.Data/Test/PostgresTest.cs +++ b/mcs/class/System.Data/Test/PostgresTest.cs @@ -1,6 +1,6 @@ /* PostgresTest.cs - based on the postgres-test.c in libgda * - * Copyright (C) 1998-2002 The GNOME Foundation + * Copyright (C) 2002 Gonzalo Paniagua Javier * Copyright (C) 2002 Daniel Morgan * * ORIGINAL AUTHOR: @@ -58,7 +58,20 @@ namespace TestSystemDataSqlClient { "time_value time, " + "date_value date, " + "timestamp_value timestamp, " + - "null_value char(1) " + + "null_boolean_value boolean, " + + "null_int2_value smallint, " + + "null_int4_value integer, " + + "null_bigint_value bigint, " + + "null_float_value real, " + + "null_double_value double precision, " + + "null_numeric_value numeric(15, 3), " + + "null_char_value char(50), " + + "null_varchar_value varchar(20), " + + "null_text_value text, " + + "null_point_value point, " + + "null_time_value time, " + + "null_date_value date, " + + "null_timestamp_value timestamp " + ")"; createCommand.ExecuteNonQuery (); @@ -129,18 +142,34 @@ namespace TestSystemDataSqlClient { selectCommand.CommandText = "select " + - "boolean_value, " + - "int2_value, " + - "int4_value, " + - "bigint_value, " + - "float_value, " + - "double_value, " + - "char_value, " + - "varchar_value, " + - "text_value, " + - "time_value, " + - "date_value, " + - "timestamp_value " + + "boolean_value, " + + "int2_value, " + + "int4_value, " + + "bigint_value, " + + "float_value, " + + "double_value, " + + "numeric_value, " + + "char_value, " + + "varchar_value, " + + "text_value, " + + "point_value, " + + "time_value, " + + "date_value, " + + "timestamp_value, " + + "null_boolean_value, " + + "null_int2_value, " + + "null_int4_value, " + + "null_bigint_value, " + + "null_float_value, " + + "null_double_value, " + + "null_numeric_value, " + + "null_char_value, " + + "null_varchar_value, " + + "null_text_value, " + + "null_point_value, " + + "null_time_value, " + + "null_date_value, " + + "null_timestamp_value " + "from mono_postgres_test"; reader = selectCommand.ExecuteReader (); @@ -227,7 +256,7 @@ namespace TestSystemDataSqlClient { /* Select aggregates */ SelectAggregate (cnc, "count(*)"); - // SelectAggregate (cnc, "avg(int4_value)"); + //SelectAggregate (cnc, "avg(int4_value)"); SelectAggregate (cnc, "min(text_value)"); SelectAggregate (cnc, "max(int4_value)"); SelectAggregate (cnc, "sum(int4_value)"); @@ -257,16 +286,31 @@ namespace TestSystemDataSqlClient { }
int nRows = 0;
+ string metadataValue;
+ string dataValue;
+ string output;
// Read and display the rows
while(reader.Read()) {
Console.WriteLine ("Row " + nRows + ":");
for(c = 0; c < reader.FieldCount; c++) {
- Console.WriteLine (
+
+ // column meta data
+ metadataValue =
" Col " +
c + ": " +
- dt.Columns[c].ColumnName +
- ": " +
- reader.GetValue(c));
+ dt.Columns[c].ColumnName;
+
+ // column data
+ if(reader.IsDBNull(c) == true)
+ dataValue = " is NULL";
+ else
+ dataValue =
+ ": " +
+ reader.GetValue(c);
+
+ // display column meta data and data
+ output = metadataValue + dataValue;
+ Console.WriteLine(output);
}
nRows++;
diff --git a/mcs/class/System.Data/Test/ReadPostgresData.cs b/mcs/class/System.Data/Test/ReadPostgresData.cs index a8dc45835f1..c1fc05b0a19 100644 --- a/mcs/class/System.Data/Test/ReadPostgresData.cs +++ b/mcs/class/System.Data/Test/ReadPostgresData.cs @@ -5,6 +5,8 @@ // This is not meant to be used in Production, but as a // learning aid in coding class System.Data.SqlClient.SqlDataReader. // +// Bits of code were borrowed from libgda. +// // Author: // Daniel Morgan <danmorg@sc.rr.com> // @@ -23,6 +25,8 @@ namespace LearnToCreateSqlDataReader public static object OidTypeToSystem (int oid, string value) { object obj = null; + Console.WriteLine("===== oid: " + oid + " value: " + value); + switch(oid) { case 1043: // varchar Console.WriteLine("oid 1023 varchar ==> String found"); @@ -242,20 +246,17 @@ namespace LearnToCreateSqlDataReader public class ReadPostgresData { - static void Test() { + static void Test(String sConnInfo) { String errorMessage; IntPtr pgConn; - String sConnInfo; PostgresLibrary.ConnStatusType connStatus; String sQuery; IntPtr pgResult; - - sConnInfo = "host=localhost dbname=test user=danmorg password=viewsonic"; sQuery = - "select tid, tdesc " + + "select tid, tdesc, aint4, abpchar " + "from sometable "; pgConn = PostgresLibrary.PQconnectdb (sConnInfo); @@ -267,10 +268,11 @@ namespace LearnToCreateSqlDataReader Console.WriteLine("CONNECTION_OK"); + Console.WriteLine("SQL: " + sQuery); pgResult = PostgresLibrary.PQexec(pgConn, sQuery); PostgresLibrary.ExecStatusType execStatus; - + execStatus = PostgresLibrary. PQresultStatus (pgResult); @@ -390,7 +392,7 @@ namespace LearnToCreateSqlDataReader } - public static object ExecuteScalar(string sql) { + public static object ExecuteScalar(string sConnInfo, string sQuery) { object obj = null; // return int nRow; @@ -399,16 +401,10 @@ namespace LearnToCreateSqlDataReader String errorMessage; IntPtr pgConn; - String sConnInfo; PostgresLibrary.ConnStatusType connStatus; - String sQuery; IntPtr pgResult; - - sConnInfo = "host=localhost dbname=test user=danmorg password=viewsonic"; - - sQuery = sql; - + pgConn = PostgresLibrary.PQconnectdb (sConnInfo); connStatus = PostgresLibrary.PQstatus (pgConn); @@ -483,6 +479,8 @@ namespace LearnToCreateSqlDataReader columnIsNull = PostgresLibrary. PQgetisnull(pgResult, nRow, nCol); + + // isNull = *thevalue != '\0' ? FALSE : PQgetisnull (pg_res, rownum, i); Console.WriteLine("Data is " + (columnIsNull == 0 ? "NOT NULL" : "NULL")); @@ -528,20 +526,23 @@ namespace LearnToCreateSqlDataReader return obj; } - static void TestExecuteScalar() { + static void TestExecuteScalar(String connString) { String selectStatement; try { selectStatement = "select count(*) " + "from sometable"; - Int64 myCount = (Int64) ExecuteScalar(selectStatement); + + Int64 myCount = (Int64) ExecuteScalar(connString, + selectStatement); Console.WriteLine("Count: " + myCount); selectStatement = "select max(tdesc) " + "from sometable"; - string myMax = (string) ExecuteScalar(selectStatement); + string myMax = (string) ExecuteScalar(connString, + selectStatement); Console.WriteLine("Max: " + myMax); } catch(Exception e) { @@ -553,9 +554,18 @@ namespace LearnToCreateSqlDataReader [STAThread] static void Main(string[] args) { - // Test(); - - // TestExecuteScalar(); + // PostgreSQL DBMS Connection String + // Notice how the parameters are separated with spaces + // An OLE-DB Connection String uses semicolons to + // separate parameters. + String sConnInfo = + "host=localhost " + + "dbname=test " + + "user=postgres"; + + Test(sConnInfo); + + TestExecuteScalar(sConnInfo); Type t; int oid; diff --git a/mcs/class/System.Data/Test/TestExecuteScalar.cs b/mcs/class/System.Data/Test/TestExecuteScalar.cs index 96b10ab6b2a..b5575cab245 100644 --- a/mcs/class/System.Data/Test/TestExecuteScalar.cs +++ b/mcs/class/System.Data/Test/TestExecuteScalar.cs @@ -50,8 +50,7 @@ namespace TestSystemDataSqlClient connectionString = "host=localhost;" + "dbname=test;" + - "user=danmorg;" + - "password=viewsonic"; + "user=postgres"; try {
con = new SqlConnection(connectionString);
diff --git a/mcs/class/System.Data/Test/TestSqlDataReader.cs b/mcs/class/System.Data/Test/TestSqlDataReader.cs index e056782a730..9e0629ddc7b 100644 --- a/mcs/class/System.Data/Test/TestSqlDataReader.cs +++ b/mcs/class/System.Data/Test/TestSqlDataReader.cs @@ -32,9 +32,8 @@ namespace TestSystemDataSqlClient connectionString = "host=localhost;" + "dbname=test;" + - "user=danmorg;" + - "password=viewsonic"; -
+ "user=postgres"; +
sql = "select tid, tdesc, aint4, abpchar " +
"from sometable";
diff --git a/mcs/class/System.Data/Test/TestSqlException.cs b/mcs/class/System.Data/Test/TestSqlException.cs index 517ef72e140..294a1ddfba3 100644 --- a/mcs/class/System.Data/Test/TestSqlException.cs +++ b/mcs/class/System.Data/Test/TestSqlException.cs @@ -44,8 +44,7 @@ namespace TestSystemDataSqlClient connectionString = "host=localhost;" + "dbname=test;" + - "user=danmorg;" + - "password=viewsonic"; + "user=postgres"; insertStatement = "insert into NoSuchTable " + diff --git a/mcs/class/System.Data/Test/TestSqlInsert.cs b/mcs/class/System.Data/Test/TestSqlInsert.cs index 4a968e6305f..d8d31348eff 100644 --- a/mcs/class/System.Data/Test/TestSqlInsert.cs +++ b/mcs/class/System.Data/Test/TestSqlInsert.cs @@ -45,8 +45,7 @@ namespace TestSystemDataSqlClient connectionString = "host=localhost;" + "dbname=test;" + - "user=danmorg;" + - "password=viewsonic"; + "user=postgres"; insertStatement = "insert into sometable " + diff --git a/mcs/class/System.Data/Test/TestSqlIsolationLevel.cs b/mcs/class/System.Data/Test/TestSqlIsolationLevel.cs index caeaf18cc81..8f0f2823222 100644 --- a/mcs/class/System.Data/Test/TestSqlIsolationLevel.cs +++ b/mcs/class/System.Data/Test/TestSqlIsolationLevel.cs @@ -44,8 +44,7 @@ namespace TestSystemDataSqlClient connectionString = "host=localhost;" + "dbname=test;" + - "user=danmorg;" + - "password=viewsonic"; + "user=postgres"; insertStatement = "insert into sometable " + |