2 // TestSqlParameters.cs - test parameters for the PostgreSQL .NET Data Provider in Mono
3 // using PgSqlParameter and PgSqlParameterCollection
5 // Note: it currently only tests input parameters. Output is next on the list.
6 // Then output/input and return parameters.
9 // Daniel Morgan <danmorg@sc.rr.com>
11 // (c)copyright 2002 Daniel Morgan
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
;
40 using Mono
.Data
.PostgreSqlClient
;
42 namespace TestSystemDataPgSqlClient
{
44 public class TestParameters
{
45 public static void Main() {
46 Console
.WriteLine("** Start Test...");
48 String connectionString
= null;
55 Console
.WriteLine("** Creating connection...");
56 con
= new PgSqlConnection(connectionString
);
57 Console
.WriteLine("** opening connection...");
60 string tableName
= "pg_type";
63 sql
= "SELECT * FROM PG_TABLES WHERE TABLENAME = :inTableName";
65 Console
.WriteLine("** Creating command...");
66 PgSqlCommand cmd
= new PgSqlCommand(sql
, con
);
68 // add parameter for inTableName
69 Console
.WriteLine("** Create parameter...");
70 PgSqlParameter parm
= new PgSqlParameter("inTableName", DbType
.String
);
72 Console
.WriteLine("** set dbtype of parameter to string");
73 parm
.DbType
= DbType
.String
;
75 Console
.WriteLine("** set direction of parameter to input");
76 parm
.Direction
= ParameterDirection
.Input
;
78 Console
.WriteLine("** set value to the tableName string...");
79 parm
.Value
= tableName
;
81 Console
.WriteLine("** add parameter to parameters collection in the command...");
82 cmd
.Parameters
.Add(parm
);
85 Console
.WriteLine("** ExecuteReader()...");
87 rdr
= cmd
.ExecuteReader();
89 Console
.WriteLine("[][] And now we are going to our results [][]...");
94 Console
.WriteLine("Result Set " + results
+ "...");
96 // get the DataTable that holds
98 DataTable dt
= rdr
.GetSchemaTable();
100 // number of columns in the table
101 Console
.WriteLine(" Total Columns: " +
104 // display the schema
105 foreach (DataRow schemaRow
in dt
.Rows
) {
106 foreach (DataColumn schemaCol
in dt
.Columns
)
107 Console
.WriteLine(schemaCol
.ColumnName
+
109 schemaRow
[schemaCol
]);
113 string output
, metadataValue
, dataValue
;
116 // Read and display the rows
118 Console
.WriteLine(" Row " + nRows
+ ": ");
120 for(c
= 0; c
< rdr
.FieldCount
; c
++) {
122 DataRow dr
= dt
.Rows
[c
];
129 if(rdr
.IsDBNull(c
) == true)
130 dataValue
= " is NULL";
136 // display column meta data and data
137 output
= metadataValue
+ dataValue
;
138 Console
.WriteLine(output
);
142 Console
.WriteLine(" Total Rows: " +
144 } while(rdr
.NextResult());
145 Console
.WriteLine("Total Result sets: " + results
);