X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mcs%2Fclass%2FSystem.Data%2FTest%2FTestSqlParameters.cs;h=9c309d650b0a5f2d64a2b3f1f944cd5967ec32af;hb=234225d112c4b018b8d1796f4c06a15812137500;hp=1858f5578300fe181805d4bad9842a6796f13dd7;hpb=6d551e483ade10a775075a707d83995773e1db56;p=mono.git diff --git a/mcs/class/System.Data/Test/TestSqlParameters.cs b/mcs/class/System.Data/Test/TestSqlParameters.cs index 1858f557830..9c309d650b0 100644 --- a/mcs/class/System.Data/Test/TestSqlParameters.cs +++ b/mcs/class/System.Data/Test/TestSqlParameters.cs @@ -1,6 +1,6 @@ // // TestSqlParameters.cs - test parameters for the PostgreSQL .NET Data Provider in Mono -// using *Parameter and *ParameterCollection +// using PgSqlParameter and PgSqlParameterCollection // // Note: it currently only tests input parameters. Output is next on the list. // Then output/input and return parameters. @@ -10,13 +10,36 @@ // // (c)copyright 2002 Daniel Morgan // + +// +// 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. +// using System; using System.Collections; using System.Data; -using System.Data.SqlClient; +using Mono.Data.PostgreSqlClient; -namespace TestSystemDataSqlClient { +namespace TestSystemDataPgSqlClient { public class TestParameters { public static void Main() { @@ -28,9 +51,9 @@ namespace TestSystemDataSqlClient { "dbname=test;" + "user=postgres"; - SqlConnection con; + PgSqlConnection con; Console.WriteLine("** Creating connection..."); - con = new SqlConnection(connectionString); + con = new PgSqlConnection(connectionString); Console.WriteLine("** opening connection..."); con.Open(); @@ -40,24 +63,29 @@ namespace TestSystemDataSqlClient { sql = "SELECT * FROM PG_TABLES WHERE TABLENAME = :inTableName"; Console.WriteLine("** Creating command..."); - SqlCommand cmd = new SqlCommand(sql, con); + PgSqlCommand cmd = new PgSqlCommand(sql, con); // add parameter for inTableName Console.WriteLine("** Create parameter..."); - SqlParameter parm = new SqlParameter("inTableName", SqlDbType.Text); + PgSqlParameter parm = new PgSqlParameter("inTableName", DbType.String); + Console.WriteLine("** set dbtype of parameter to string"); parm.DbType = DbType.String; + Console.WriteLine("** set direction of parameter to input"); parm.Direction = ParameterDirection.Input; + Console.WriteLine("** set value to the tableName string..."); parm.Value = tableName; Console.WriteLine("** add parameter to parameters collection in the command..."); cmd.Parameters.Add(parm); - SqlDataReader rdr; + PgSqlDataReader rdr; Console.WriteLine("** ExecuteReader()..."); + rdr = cmd.ExecuteReader(); + Console.WriteLine("[][] And now we are going to our results [][]..."); int c; int results = 0; @@ -74,14 +102,15 @@ namespace TestSystemDataSqlClient { dt.Columns.Count); // display the schema - for(c = 0; c < dt.Columns.Count; c++) { - Console.WriteLine(" Column Name: " + - dt.Columns[c].ColumnName); - Console.WriteLine(" MaxLength: " + - dt.Columns[c].MaxLength); - Console.WriteLine(" Type: " + - dt.Columns[c].DataType); + foreach (DataRow schemaRow in dt.Rows) { + foreach (DataColumn schemaCol in dt.Columns) + Console.WriteLine(schemaCol.ColumnName + + " = " + + schemaRow[schemaCol]); + Console.WriteLine(); } + + string output, metadataValue, dataValue; int nRows = 0; // Read and display the rows @@ -89,13 +118,24 @@ namespace TestSystemDataSqlClient { Console.WriteLine(" Row " + nRows + ": "); for(c = 0; c < rdr.FieldCount; c++) { + // column meta data + DataRow dr = dt.Rows[c]; + metadataValue = + " Col " + + c + ": " + + dr["ColumnName"]; + + // column data if(rdr.IsDBNull(c) == true) - Console.WriteLine(" " + - rdr.GetName(c) + " is DBNull"); + dataValue = " is NULL"; else - Console.WriteLine(" " + - rdr.GetName(c) + ": " + - rdr[c].ToString()); + dataValue = + ": " + + rdr.GetValue(c); + + // display column meta data and data + output = metadataValue + dataValue; + Console.WriteLine(output); } nRows++; }