//\r
// TestSqlParameters.cs - test parameters for the PostgreSQL .NET Data Provider in Mono\r
-// using *Parameter and *ParameterCollection\r
+// using PgSqlParameter and PgSqlParameterCollection\r
//\r
// Note: it currently only tests input parameters. Output is next on the list.\r
// Then output/input and return parameters.\r
//\r
// (c)copyright 2002 Daniel Morgan\r
//\r
+
+//
+// Copyright (C) 2004 Novell, Inc (http://www.novell.com)
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
\r
using System;\r
using System.Collections;\r
using System.Data;\r
-using System.Data.SqlClient;\r
+using Mono.Data.PostgreSqlClient;\r
\r
-namespace TestSystemDataSqlClient {\r
+namespace TestSystemDataPgSqlClient {\r
\r
public class TestParameters {\r
public static void Main() {\r
"dbname=test;" +
"user=postgres";
\r
- SqlConnection con;\r
+ PgSqlConnection con;\r
Console.WriteLine("** Creating connection...");\r
- con = new SqlConnection(connectionString);\r
+ con = new PgSqlConnection(connectionString);\r
Console.WriteLine("** opening connection...");\r
con.Open();\r
\r
sql = "SELECT * FROM PG_TABLES WHERE TABLENAME = :inTableName";\r
\r
Console.WriteLine("** Creating command...");\r
- SqlCommand cmd = new SqlCommand(sql, con);\r
+ PgSqlCommand cmd = new PgSqlCommand(sql, con);\r
\r
// add parameter for inTableName\r
Console.WriteLine("** Create parameter...");\r
- SqlParameter parm = new SqlParameter("inTableName", SqlDbType.Text);\r
+ PgSqlParameter parm = new PgSqlParameter("inTableName", DbType.String);\r
+ \r
Console.WriteLine("** set dbtype of parameter to string");\r
parm.DbType = DbType.String;\r
+ \r
Console.WriteLine("** set direction of parameter to input");\r
parm.Direction = ParameterDirection.Input;\r
+ \r
Console.WriteLine("** set value to the tableName string...");\r
parm.Value = tableName;\r
\r
Console.WriteLine("** add parameter to parameters collection in the command...");\r
cmd.Parameters.Add(parm);\r
\r
- SqlDataReader rdr;\r
+ PgSqlDataReader rdr;\r
Console.WriteLine("** ExecuteReader()...");\r
+ \r
rdr = cmd.ExecuteReader();\r
+ \r
Console.WriteLine("[][] And now we are going to our results [][]...");\r
int c;\r
int results = 0;\r
dt.Columns.Count);\r
\r
// display the schema\r
- for(c = 0; c < dt.Columns.Count; c++) {\r
- Console.WriteLine(" Column Name: " + \r
- dt.Columns[c].ColumnName);\r
- Console.WriteLine(" MaxLength: " +\r
- dt.Columns[c].MaxLength);\r
- Console.WriteLine(" Type: " +\r
- dt.Columns[c].DataType);\r
+ foreach (DataRow schemaRow in dt.Rows) {\r
+ foreach (DataColumn schemaCol in dt.Columns)\r
+ Console.WriteLine(schemaCol.ColumnName + \r
+ " = " + \r
+ schemaRow[schemaCol]);\r
+ Console.WriteLine();\r
}\r
+\r
+ string output, metadataValue, dataValue;\r
int nRows = 0;\r
\r
// Read and display the rows\r
Console.WriteLine(" Row " + nRows + ": ");\r
\r
for(c = 0; c < rdr.FieldCount; c++) {\r
+ // column meta data \r
+ DataRow dr = dt.Rows[c];\r
+ metadataValue = \r
+ " Col " + \r
+ c + ": " + \r
+ dr["ColumnName"];\r
+ \r
+ // column data\r
if(rdr.IsDBNull(c) == true)\r
- Console.WriteLine(" " + \r
- rdr.GetName(c) + " is DBNull");\r
+ dataValue = " is NULL";\r
else\r
- Console.WriteLine(" " + \r
- rdr.GetName(c) + ": " +\r
- rdr[c].ToString());\r
+ dataValue = \r
+ ": " + \r
+ rdr.GetValue(c);\r
+ \r
+ // display column meta data and data\r
+ output = metadataValue + dataValue; \r
+ Console.WriteLine(output);\r
}\r
nRows++;\r
}\r