2 // TestSqlParameters.cs - test parameters for the PostgreSQL .NET Data Provider in Mono
\r
3 // using PgSqlParameter and PgSqlParameterCollection
\r
5 // Note: it currently only tests input parameters. Output is next on the list.
\r
6 // Then output/input and return parameters.
\r
9 // Daniel Morgan <danmorg@sc.rr.com>
\r
11 // (c)copyright 2002 Daniel Morgan
\r
15 // Copyright (C) 2004 Novell, Inc (http://www.novell.com)
17 // Permission is hereby granted, free of charge, to any person obtaining
18 // a copy of this software and associated documentation files (the
19 // "Software"), to deal in the Software without restriction, including
20 // without limitation the rights to use, copy, modify, merge, publish,
21 // distribute, sublicense, and/or sell copies of the Software, and to
22 // permit persons to whom the Software is furnished to do so, subject to
23 // the following conditions:
25 // The above copyright notice and this permission notice shall be
26 // included in all copies or substantial portions of the Software.
28 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
29 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
30 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
31 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
32 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
33 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
34 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
38 using System.Collections;
\r
40 using Mono.Data.PostgreSqlClient;
\r
42 namespace TestSystemDataPgSqlClient {
\r
44 public class TestParameters {
\r
45 public static void Main() {
\r
46 Console.WriteLine("** Start Test...");
\r
48 String connectionString = null;
\r
54 PgSqlConnection con;
\r
55 Console.WriteLine("** Creating connection...");
\r
56 con = new PgSqlConnection(connectionString);
\r
57 Console.WriteLine("** opening connection...");
\r
60 string tableName = "pg_type";
\r
63 sql = "SELECT * FROM PG_TABLES WHERE TABLENAME = :inTableName";
\r
65 Console.WriteLine("** Creating command...");
\r
66 PgSqlCommand cmd = new PgSqlCommand(sql, con);
\r
68 // add parameter for inTableName
\r
69 Console.WriteLine("** Create parameter...");
\r
70 PgSqlParameter parm = new PgSqlParameter("inTableName", DbType.String);
\r
72 Console.WriteLine("** set dbtype of parameter to string");
\r
73 parm.DbType = DbType.String;
\r
75 Console.WriteLine("** set direction of parameter to input");
\r
76 parm.Direction = ParameterDirection.Input;
\r
78 Console.WriteLine("** set value to the tableName string...");
\r
79 parm.Value = tableName;
\r
81 Console.WriteLine("** add parameter to parameters collection in the command...");
\r
82 cmd.Parameters.Add(parm);
\r
84 PgSqlDataReader rdr;
\r
85 Console.WriteLine("** ExecuteReader()...");
\r
87 rdr = cmd.ExecuteReader();
\r
89 Console.WriteLine("[][] And now we are going to our results [][]...");
\r
94 Console.WriteLine("Result Set " + results + "...");
\r
96 // get the DataTable that holds
\r
98 DataTable dt = rdr.GetSchemaTable();
\r
100 // number of columns in the table
\r
101 Console.WriteLine(" Total Columns: " +
\r
104 // display the schema
\r
105 foreach (DataRow schemaRow in dt.Rows) {
\r
106 foreach (DataColumn schemaCol in dt.Columns)
\r
107 Console.WriteLine(schemaCol.ColumnName +
\r
109 schemaRow[schemaCol]);
\r
110 Console.WriteLine();
\r
113 string output, metadataValue, dataValue;
\r
116 // Read and display the rows
\r
117 while(rdr.Read()) {
\r
118 Console.WriteLine(" Row " + nRows + ": ");
\r
120 for(c = 0; c < rdr.FieldCount; c++) {
\r
121 // column meta data
\r
122 DataRow dr = dt.Rows[c];
\r
129 if(rdr.IsDBNull(c) == true)
\r
130 dataValue = " is NULL";
\r
136 // display column meta data and data
\r
137 output = metadataValue + dataValue;
\r
138 Console.WriteLine(output);
\r
142 Console.WriteLine(" Total Rows: " +
\r
144 } while(rdr.NextResult());
\r
145 Console.WriteLine("Total Result sets: " + results);
\r