1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Data ;
4
- using Microsoft . Data . SqlClient ;
4
+ using Npgsql ;
5
5
using System . IO ;
6
6
7
7
public class PGTest
8
8
{
9
9
public class Tests
10
10
{
11
- private SqlConnection conn ;
12
- private SqlCommand cmd ;
11
+ private NpgsqlConnection conn ;
12
+ private NpgsqlCommand cmd ;
13
13
private List < Test > tests = new List < Test > ( ) ;
14
14
15
15
public void Connect ( string ip , int port , string user , string password )
16
16
{
17
- string connectionString = $ "Server ={ ip } , { port } ;User Id ={ user } ;Password={ password } ;";
17
+ string connectionString = $ "Host ={ ip } ;Port= { port } ;Username ={ user } ;Password={ password } ;Database=postgres ;";
18
18
try
19
19
{
20
- conn = new SqlConnection ( connectionString ) ;
20
+ conn = new NpgsqlConnection ( connectionString ) ;
21
21
conn . Open ( ) ;
22
22
cmd = conn . CreateCommand ( ) ;
23
23
cmd . CommandType = CommandType . Text ;
24
24
}
25
- catch ( SqlException e )
25
+ catch ( NpgsqlException e )
26
26
{
27
27
throw new Exception ( $ "Error connecting to database: { e . Message } ", e ) ;
28
28
}
@@ -35,7 +35,7 @@ public void Disconnect()
35
35
cmd . Dispose ( ) ;
36
36
conn . Close ( ) ;
37
37
}
38
- catch ( SqlException e )
38
+ catch ( NpgsqlException e )
39
39
{
40
40
throw new Exception ( e . Message ) ;
41
41
}
@@ -97,7 +97,7 @@ public Test(string query, string[][] expectedResults)
97
97
this . expectedResults = expectedResults ;
98
98
}
99
99
100
- public bool Run ( SqlCommand cmd )
100
+ public bool Run ( NpgsqlCommand cmd )
101
101
{
102
102
try
103
103
{
@@ -125,15 +125,11 @@ public bool Run(SqlCommand cmd)
125
125
{
126
126
for ( int col = 0 ; col < expectedResults [ rows ] . Length ; col ++ )
127
127
{
128
- string result = reader . GetString ( col ) ;
128
+ string result = reader . GetValue ( col ) . ToString ( ) . Trim ( ) ;
129
129
if ( expectedResults [ rows ] [ col ] != result )
130
130
{
131
131
Console . Error . WriteLine ( $ "Expected:\n '{ expectedResults [ rows ] [ col ] } '") ;
132
- Console . Error . WriteLine ( $ "Result:\n '{ result } '\n Rest of the results:") ;
133
- while ( reader . Read ( ) )
134
- {
135
- Console . Error . WriteLine ( reader . GetString ( 0 ) ) ;
136
- }
132
+ Console . Error . WriteLine ( $ "Result:\n '{ result } '") ;
137
133
return false ;
138
134
}
139
135
}
@@ -148,7 +144,7 @@ public bool Run(SqlCommand cmd)
148
144
return true ;
149
145
}
150
146
}
151
- catch ( SqlException e )
147
+ catch ( NpgsqlException e )
152
148
{
153
149
Console . Error . WriteLine ( e . Message ) ;
154
150
return false ;
0 commit comments