2004-06-18 Francisco Figueiredo Jr. <fxjrlists@yahoo.com.br>
[mono.git] / mcs / class / Npgsql / Test / CommandTests.cs
1 // created on 30/11/2002 at 22:35
2 // 
3 // Author:
4 //      Francisco Figueiredo Jr. <fxjrlists@yahoo.com>
5 //
6 //      Copyright (C) 2002 The Npgsql Development Team
7 //      npgsql-general@gborg.postgresql.org
8 //      http://gborg.postgresql.org/project/npgsql/projdisplay.php
9 //
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
14 // 
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 // Lesser General Public License for more details.
19 // 
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
23
24 using System;
25 using Npgsql;
26 using NUnit.Framework;
27 using NUnit.Core;
28 using System.Data;
29 using System.Globalization;
30 using NpgsqlTypes;
31
32 namespace NpgsqlTests
33 {
34         
35         [TestFixture]
36         public class CommandTests
37         {
38                 private NpgsqlConnection        _conn = null;
39                 private String                                          _connString = "Server=localhost;User ID=npgsql_tests;Password=npgsql_tests;Database=npgsql_tests;SSL=yes;maxpoolsize=2;";
40                 
41                 [SetUp]
42                 protected void SetUp()
43                 {
44                         //NpgsqlEventLog.Level = LogLevel.None;
45                         //NpgsqlEventLog.Level = LogLevel.Debug;
46                         //NpgsqlEventLog.LogName = "NpgsqlTests.LogFile";
47                         _conn = new NpgsqlConnection(_connString);
48                 }
49                 
50                 [TearDown]
51                 protected void TearDown()
52                 {
53                         if (_conn.State != ConnectionState.Closed)
54                                 _conn.Close();
55                 }
56                 
57                 
58                 [Test]
59                 public void ParametersGetName()
60                 {
61                         NpgsqlCommand command = new NpgsqlCommand();
62                         
63                         // Add parameters.
64                         command.Parameters.Add(new NpgsqlParameter(":Parameter1", DbType.Boolean));
65                         command.Parameters.Add(new NpgsqlParameter(":Parameter2", DbType.Int32));
66                         command.Parameters.Add(new NpgsqlParameter(":Parameter3", DbType.DateTime));
67                         
68                         
69                         // Get by indexers.
70                         
71                         Assertion.AssertEquals("ParametersGetName", ":Parameter1", command.Parameters[":Parameter1"].ParameterName);
72                         Assertion.AssertEquals("ParametersGetName", ":Parameter2", command.Parameters[":Parameter2"].ParameterName);
73                         Assertion.AssertEquals("ParametersGetName", ":Parameter3", command.Parameters[":Parameter3"].ParameterName);
74                                                                  
75
76                         Assertion.AssertEquals("ParametersGetName", ":Parameter1", command.Parameters[0].ParameterName);
77                         Assertion.AssertEquals("ParametersGetName", ":Parameter2", command.Parameters[1].ParameterName);
78                         Assertion.AssertEquals("ParametersGetName", ":Parameter3", command.Parameters[2].ParameterName);                                                             
79                         
80                         
81                         
82                 }
83                 
84                 [Test]
85                 public void EmptyQuery()
86                 {
87                         _conn.Open();
88                 
89                         NpgsqlCommand command = new NpgsqlCommand(";", _conn);
90                         command.ExecuteNonQuery();
91                         
92                 }
93                 [Test]
94                 [ExpectedException(typeof(ArgumentNullException))]
95                 public void NoNameParameterAdd()
96                 {
97                         NpgsqlCommand command = new NpgsqlCommand();
98                         
99                         command.Parameters.Add(new NpgsqlParameter());
100                         
101                 }
102                 
103                 [Test]
104                 public void FunctionCallFromSelect()
105                 {
106                         _conn.Open();
107                         
108                         NpgsqlCommand command = new NpgsqlCommand("select * from funcB()", _conn);
109                         
110                         NpgsqlDataReader reader = command.ExecuteReader();
111                         
112                         Assertion.AssertNotNull(reader);
113                         //reader.FieldCount
114                         
115                 }
116                 
117                 [Test]
118                 public void ExecuteScalar()
119                 {
120                         _conn.Open();
121                         
122                         NpgsqlCommand command = new NpgsqlCommand("select count(*) from tablea", _conn);
123                         
124                         Object result = command.ExecuteScalar();
125                         
126                         Assertion.AssertEquals(5, result);
127                         //reader.FieldCount
128                         
129                 }
130         
131                 [Test]
132                 public void FunctionCallReturnSingleValue()
133                 {
134                         _conn.Open();
135                         
136                         NpgsqlCommand command = new NpgsqlCommand("funcC()", _conn);
137                         command.CommandType = CommandType.StoredProcedure;
138                                                 
139                         Object result = command.ExecuteScalar();
140                         
141                         Assertion.AssertEquals(5, result);
142                         //reader.FieldCount
143                         
144                 }
145                 
146                 
147                 [Test]
148                 public void FunctionCallReturnSingleValueWithPrepare()
149                 {
150                         _conn.Open();
151                         
152                         NpgsqlCommand command = new NpgsqlCommand("funcC()", _conn);
153                         command.CommandType = CommandType.StoredProcedure;
154                         
155                         command.Prepare();
156                         Object result = command.ExecuteScalar();
157                         
158                         Assertion.AssertEquals(5, result);
159                         //reader.FieldCount
160                         
161                 }
162                 
163                 [Test]
164                 public void FunctionCallWithParametersReturnSingleValue()
165                 {
166                         _conn.Open();
167                         
168                         NpgsqlCommand command = new NpgsqlCommand("funcC(:a)", _conn);
169                         command.CommandType = CommandType.StoredProcedure;
170                         
171                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Int32));
172                                                 
173                         command.Parameters[0].Value = 4;
174                                                 
175                         Int64 result = (Int64) command.ExecuteScalar();
176                         
177                         Assertion.AssertEquals(1, result);
178                         
179                         
180                 }
181                 
182                 
183                 [Test]
184                 public void FunctionCallWithParametersPrepareReturnSingleValue()
185                 {
186                         _conn.Open();
187                         
188                         NpgsqlCommand command = new NpgsqlCommand("funcC(:a)", _conn);
189                         command.CommandType = CommandType.StoredProcedure;
190                         
191                         
192                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Int32));
193                         
194                         Assertion.AssertEquals(1, command.Parameters.Count);
195                         command.Prepare();
196                         
197                         
198                         command.Parameters[0].Value = 4;
199                                                 
200                         Int64 result = (Int64) command.ExecuteScalar();
201                         
202                         Assertion.AssertEquals(1, result);
203                         
204                         
205                 }
206                 
207                 [Test]
208                 public void FunctionCallReturnResultSet()
209                 {
210                         _conn.Open();
211                         
212                         NpgsqlCommand command = new NpgsqlCommand("funcB()", _conn);
213                         command.CommandType = CommandType.StoredProcedure;
214                         
215                         NpgsqlDataReader dr = command.ExecuteReader();
216                         
217                         
218                         
219                         
220                 }
221                 
222                 
223                 [Test]
224                 public void CursorStatement()
225                 {
226                         
227                         _conn.Open();
228                         
229                         Int32 i = 0;
230                         
231                         NpgsqlTransaction t = _conn.BeginTransaction();
232                         
233                         NpgsqlCommand command = new NpgsqlCommand("declare te cursor for select * from tablea;", _conn);
234                         
235                         command.ExecuteNonQuery();
236                         
237                         command.CommandText = "fetch forward 3 in te;";
238                         
239                         NpgsqlDataReader dr = command.ExecuteReader();
240                         
241                         
242                         while (dr.Read())
243                         {
244                                 i++;
245                         }
246                         
247                         Assertion.AssertEquals(3, i);
248                         
249                         
250                         i = 0;
251                         
252                         command.CommandText = "fetch backward 1 in te;";
253                         
254                         NpgsqlDataReader dr2 = command.ExecuteReader();
255                         
256                         while (dr2.Read())
257                         {
258                                 i++;
259                         }
260                         
261                         Assertion.AssertEquals(1, i);
262                         
263                         command.CommandText = "close te;";
264                         
265                         command.ExecuteNonQuery();
266                         
267                         t.Commit();
268                         
269                         
270                         
271                 }
272                 
273                 [Test]
274                 public void PreparedStatementNoParameters()
275                 {
276                         _conn.Open();
277                         
278                         NpgsqlCommand command = new NpgsqlCommand("select * from tablea;", _conn);
279                         
280                         command.Prepare();
281                         
282                         command.Prepare();
283                         
284                         NpgsqlDataReader dr = command.ExecuteReader();
285                         
286                                                 
287                 }
288                 
289                 [Test]
290                 public void PreparedStatementWithParameters()
291                 {
292                         _conn.Open();
293                         
294                         NpgsqlCommand command = new NpgsqlCommand("select * from tablea where field_int4 = :a and field_int8 = :b;", _conn);
295                         
296                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Int32));
297                         command.Parameters.Add(new NpgsqlParameter("b", DbType.Int64));
298                         
299                         Assertion.AssertEquals(2, command.Parameters.Count);
300                         
301                         Assertion.AssertEquals(DbType.Int32, command.Parameters[0].DbType);
302                         
303                         command.Prepare();
304                         
305                         command.Parameters[0].Value = 3;
306                         command.Parameters[1].Value = 5;
307                         
308                         NpgsqlDataReader dr = command.ExecuteReader();
309                         
310                         
311                         
312                         
313                 }
314                 
315                 [Test]
316                 [ExpectedException(typeof(InvalidOperationException))]
317                 public void ListenNotifySupport()
318                 {
319                   
320                   _conn.Open();
321                   
322                   NpgsqlCommand command = new NpgsqlCommand("listen notifytest;", _conn);
323                   command.ExecuteNonQuery();
324                   
325                   _conn.Notification += new NotificationEventHandler(NotificationSupportHelper);
326                   
327                                                                        
328                   command = new NpgsqlCommand("notify notifytest;", _conn);
329                   command.ExecuteNonQuery();
330                   
331                   
332                   
333                 }
334                 
335                 private void NotificationSupportHelper(Object sender, NpgsqlNotificationEventArgs args)
336                 {
337                   throw new InvalidOperationException();
338                 }
339                 
340                 [Test]
341                 public void DateTimeSupport()
342                 {
343                         _conn.Open();
344                         
345                         
346                         NpgsqlCommand command = new NpgsqlCommand("select field_timestamp from tableb where field_serial = 2;", _conn);
347                         
348                         DateTime d = (DateTime)command.ExecuteScalar();
349                         
350                         
351                         Assertion.AssertEquals("2002-02-02 09:00:23Z", d.ToString("u"));
352                         
353                         DateTimeFormatInfo culture = new DateTimeFormatInfo();
354                         culture.TimeSeparator = ":";
355                         DateTime dt = System.DateTime.Parse("2004-06-04 09:48:00", culture);
356
357                         command.CommandText = "insert into tableb(field_timestamp) values (:a);delete from tableb where field_serial > 4;";
358                         command.Parameters.Add(new NpgsqlParameter("a", DbType.DateTime));
359                         command.Parameters[0].Value = dt;
360                         
361                         command.ExecuteScalar();
362                         
363                 }
364                 
365                 [Test]
366                 public void DateSupport()
367                 {
368                   _conn.Open();
369                   
370                   NpgsqlCommand command = new NpgsqlCommand("select field_date from tablec where field_serial = 1;", _conn);
371                         
372                         DateTime d = (DateTime)command.ExecuteScalar();
373                         
374                         
375                         Assertion.AssertEquals("2002-03-04", d.ToString("yyyy-MM-dd"));
376                         
377                 }
378                 
379                 [Test]
380                 public void TimeSupport()
381                 {
382                   _conn.Open();
383                   
384                   NpgsqlCommand command = new NpgsqlCommand("select field_time from tablec where field_serial = 2;", _conn);
385                         
386                         DateTime d = (DateTime)command.ExecuteScalar();
387                         
388                         
389                         Assertion.AssertEquals("10:03:45.345", d.ToString("HH:mm:ss.fff"));
390                         
391                 }
392                 
393                 [Test]
394                 public void NumericSupport()
395                 {
396                         _conn.Open();
397                         
398                         
399                         NpgsqlCommand command = new NpgsqlCommand("insert into tableb(field_numeric) values (:a)", _conn);
400                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Decimal));
401                         
402                         command.Parameters[0].Value = 7.4M;
403                         
404                         Int32 rowsAdded = command.ExecuteNonQuery();
405                         
406                         Assertion.AssertEquals(1, rowsAdded);
407                         
408                         command.CommandText = "select * from tableb where field_numeric = :a";
409                         
410                         
411                         NpgsqlDataReader dr = command.ExecuteReader();
412                         dr.Read();
413                         
414                         Decimal result = dr.GetDecimal(3);
415                         
416                         
417                         command.CommandText = "delete from tableb where field_serial = (select max(field_serial) from tableb) and field_serial != 3;";
418                         command.Parameters.Clear();
419                         command.ExecuteNonQuery();
420                         
421                         
422                         Assertion.AssertEquals(7.4M, result);
423                         
424                         
425                         
426                         
427                 }
428                 
429                 [Test]
430                 public void InsertSingleValue()
431                 {
432                   _conn.Open();
433                         
434                         
435                         NpgsqlCommand command = new NpgsqlCommand("insert into tabled(field_float4) values (:a)", _conn);
436                         command.Parameters.Add(new NpgsqlParameter(":a", DbType.Single));
437                         
438                         command.Parameters[0].Value = 7.4F;
439                         
440                         Int32 rowsAdded = command.ExecuteNonQuery();
441                         
442                         Assertion.AssertEquals(1, rowsAdded);
443                         
444                         command.CommandText = "select * from tabled where field_float4 = :a";
445                         
446                         
447                         NpgsqlDataReader dr = command.ExecuteReader();
448                         dr.Read();
449                         
450                         Single result = dr.GetFloat(1);
451                         
452                         
453                         command.CommandText = "delete from tabled where field_serial > 2;";
454                         command.Parameters.Clear();
455                         command.ExecuteNonQuery();
456                         
457                         
458                         Assertion.AssertEquals(7.4F, result);
459                         
460                 }
461                 
462                 [Test]
463                 public void InsertDoubleValue()
464                 {
465                   _conn.Open();
466                         
467                         
468                         NpgsqlCommand command = new NpgsqlCommand("insert into tabled(field_float8) values (:a)", _conn);
469                         command.Parameters.Add(new NpgsqlParameter(":a", DbType.Double));
470                         
471                         command.Parameters[0].Value = 7.4D;
472                         
473                         Int32 rowsAdded = command.ExecuteNonQuery();
474                         
475                         Assertion.AssertEquals(1, rowsAdded);
476                         
477                         command.CommandText = "select * from tabled where field_float8 = :a";
478                         
479                         
480                         NpgsqlDataReader dr = command.ExecuteReader();
481                         dr.Read();
482                         
483                         Double result = dr.GetDouble(2);
484                         
485                         
486                         command.CommandText = "delete from tabled where field_serial > 2;";
487                         command.Parameters.Clear();
488                         //command.ExecuteNonQuery();
489                         
490                         
491                         Assertion.AssertEquals(7.4D, result);
492                         
493                 }
494                 
495                 [Test]
496                 public void NegativeNumericSupport()
497                 {
498                         _conn.Open();
499                         
500                         
501                         NpgsqlCommand command = new NpgsqlCommand("select * from tableb where field_serial = 4", _conn);
502                         
503                                                 
504                         NpgsqlDataReader dr = command.ExecuteReader();
505                         dr.Read();
506                         
507                         Decimal result = dr.GetDecimal(3);
508                         
509                         Assertion.AssertEquals(-4.3M, result);
510                         
511                 }
512                 
513                 [Test]
514                 public void PrecisionScaleNumericSupport()
515                 {
516                         _conn.Open();
517                         
518                         
519                         NpgsqlCommand command = new NpgsqlCommand("select * from tableb where field_serial = 4", _conn);
520                         
521                                                 
522                         NpgsqlDataReader dr = command.ExecuteReader();
523                         dr.Read();
524                         
525                         Decimal result = dr.GetDecimal(3);
526                         
527                         Assertion.AssertEquals(-4.3M, (Decimal)result);
528                         //Assertion.AssertEquals(11, result.Precision);
529                         //Assertion.AssertEquals(7, result.Scale);
530                         
531                 }
532                 
533                 [Test]
534                 public void InsertNullString()
535                 {
536                         _conn.Open();
537                         
538                         NpgsqlCommand command = new NpgsqlCommand("insert into tablea(field_text) values (:a)", _conn);
539                         
540                         command.Parameters.Add(new NpgsqlParameter("a", DbType.String));
541                         
542                         command.Parameters[0].Value = DBNull.Value;
543                         
544                         Int32 rowsAdded = command.ExecuteNonQuery();
545                         
546                         Assertion.AssertEquals(1, rowsAdded);
547                         
548                         command.CommandText = "select count(*) from tablea where field_text is null";
549                         command.Parameters.Clear();
550                         
551                         Int64 result = (Int64)command.ExecuteScalar();
552                         
553                         command.CommandText = "delete from tablea where field_serial = (select max(field_serial) from tablea) and field_serial != 4;";
554                         command.ExecuteNonQuery();
555                         
556                         Assertion.AssertEquals(4, result);
557                         
558                         
559                         
560                 }
561         
562                 [Test]
563                 public void InsertNullDateTime()
564                 {
565                         _conn.Open();
566                         
567                         NpgsqlCommand command = new NpgsqlCommand("insert into tableb(field_timestamp) values (:a)", _conn);
568                         
569                         command.Parameters.Add(new NpgsqlParameter("a", DbType.DateTime));
570                         
571                         command.Parameters[0].Value = DBNull.Value;
572                         
573                         Int32 rowsAdded = command.ExecuteNonQuery();
574                         
575                         Assertion.AssertEquals(1, rowsAdded);
576                         
577                         command.CommandText = "select count(*) from tableb where field_timestamp is null";
578                         command.Parameters.Clear();
579                         
580                         Object result = command.ExecuteScalar();
581                         
582                         command.CommandText = "delete from tableb where field_serial = (select max(field_serial) from tableb) and field_serial != 3;";
583                         command.ExecuteNonQuery();
584                         
585                         Assertion.AssertEquals(4, result);
586                         
587                         
588                         
589                 }
590                 
591                 
592                 [Test]
593                 public void InsertNullInt16()
594                 {
595                         _conn.Open();
596                         
597                         
598                         NpgsqlCommand command = new NpgsqlCommand("insert into tableb(field_int2) values (:a)", _conn);
599                         
600                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Int16));
601                         
602                         command.Parameters[0].Value = DBNull.Value;
603                         
604                         Int32 rowsAdded = command.ExecuteNonQuery();
605                         
606                         Assertion.AssertEquals(1, rowsAdded);
607                         
608                         command.CommandText = "select count(*) from tableb where field_int2 is null";
609                         command.Parameters.Clear();
610                         
611                         Object result = command.ExecuteScalar(); // The missed cast is needed as Server7.2 returns Int32 and Server7.3+ returns Int64
612                         
613                         command.CommandText = "delete from tableb where field_serial = (select max(field_serial) from tableb);";
614                         command.ExecuteNonQuery();
615                         
616                         Assertion.AssertEquals(4, result);
617                         
618                         
619                 }
620                 
621                 
622                 [Test]
623                 public void InsertNullInt32()
624                 {
625                         _conn.Open();
626                         
627                         
628                         NpgsqlCommand command = new NpgsqlCommand("insert into tablea(field_int4) values (:a)", _conn);
629                         
630                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Int32));
631                         
632                         command.Parameters[0].Value = DBNull.Value;
633                         
634                         Int32 rowsAdded = command.ExecuteNonQuery();
635                         
636                         Assertion.AssertEquals(1, rowsAdded);
637                         
638                         command.CommandText = "select count(*) from tablea where field_int4 is null";
639                         command.Parameters.Clear();
640                         
641                         Object result = command.ExecuteScalar(); // The missed cast is needed as Server7.2 returns Int32 and Server7.3+ returns Int64
642                         
643                         command.CommandText = "delete from tablea where field_serial = (select max(field_serial) from tablea);";
644                         command.ExecuteNonQuery();
645                         
646                         Assertion.AssertEquals(5, result);
647                         
648                 }
649                 
650                 
651                 [Test]
652                 public void InsertNullNumeric()
653                 {
654                         _conn.Open();
655                         
656                         
657                         NpgsqlCommand command = new NpgsqlCommand("insert into tableb(field_numeric) values (:a)", _conn);
658                         
659                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Decimal));
660                         
661                         command.Parameters[0].Value = DBNull.Value;
662                         
663                         Int32 rowsAdded = command.ExecuteNonQuery();
664                         
665                         Assertion.AssertEquals(1, rowsAdded);
666                         
667                         command.CommandText = "select count(*) from tableb where field_numeric is null";
668                         command.Parameters.Clear();
669                         
670                         Object result = command.ExecuteScalar(); // The missed cast is needed as Server7.2 returns Int32 and Server7.3+ returns Int64
671                         
672                         command.CommandText = "delete from tableb where field_serial = (select max(field_serial) from tableb);";
673                         command.ExecuteNonQuery();
674                         
675                         Assertion.AssertEquals(3, result);
676                         
677                 }
678                 
679                 [Test]
680                 public void InsertNullBoolean()
681                 {
682                         _conn.Open();
683                         
684                         
685                         NpgsqlCommand command = new NpgsqlCommand("insert into tablea(field_bool) values (:a)", _conn);
686                         
687                         command.Parameters.Add(new NpgsqlParameter("a", DbType.Boolean));
688                         
689                         command.Parameters[0].Value = DBNull.Value;
690                         
691                         Int32 rowsAdded = command.ExecuteNonQuery();
692                         
693                         Assertion.AssertEquals(1, rowsAdded);
694                         
695                         command.CommandText = "select count(*) from tablea where field_bool is null";
696                         command.Parameters.Clear();
697                         
698                         Object result = command.ExecuteScalar(); // The missed cast is needed as Server7.2 returns Int32 and Server7.3+ returns Int64
699                         
700                         command.CommandText = "delete from tablea where field_serial = (select max(field_serial) from tablea);";
701                         command.ExecuteNonQuery();
702                         
703                         Assertion.AssertEquals(5, result);
704                         
705                 }
706         
707         [Test]
708                 public void AnsiStringSupport()
709                 {
710                         _conn.Open();
711                         
712                         NpgsqlCommand command = new NpgsqlCommand("insert into tablea(field_text) values (:a)", _conn);
713                         
714                         command.Parameters.Add(new NpgsqlParameter("a", DbType.AnsiString));
715                         
716                         command.Parameters[0].Value = "TesteAnsiString";
717                         
718                         Int32 rowsAdded = command.ExecuteNonQuery();
719                         
720                         Assertion.AssertEquals(1, rowsAdded);
721                         
722                         command.CommandText = String.Format("select count(*) from tablea where field_text = '{0}'", command.Parameters[0].Value);
723                         command.Parameters.Clear();
724                         
725                         Object result = command.ExecuteScalar(); // The missed cast is needed as Server7.2 returns Int32 and Server7.3+ returns Int64
726                         
727                         command.CommandText = "delete from tablea where field_serial = (select max(field_serial) from tablea);";
728                         command.ExecuteNonQuery();
729                         
730                         Assertion.AssertEquals(1, result);
731                         
732                 }
733                 
734                 
735         [Test]
736                 public void MultipleQueriesFirstResultsetEmpty()
737                 {
738                         _conn.Open();
739                         
740                         NpgsqlCommand command = new NpgsqlCommand("insert into tablea(field_text) values ('a'); select count(*) from tablea;", _conn);
741             
742             Object result = command.ExecuteScalar();
743                         
744             
745             command.CommandText = "delete from tablea where field_serial > 5";
746             command.ExecuteNonQuery();
747             
748             command.CommandText = "select * from tablea where field_serial = 0";
749             command.ExecuteScalar();
750             
751             
752             Assertion.AssertEquals(6, result);
753             
754             
755                 }
756         
757         [Test]
758         [ExpectedException(typeof(NpgsqlException))]
759         public void ConnectionStringWithInvalidParameters()
760         {
761             NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=npgsql_tests;Password=j");
762             
763             NpgsqlCommand command = new NpgsqlCommand("select * from tablea", conn);
764             
765             command.Connection.Open();
766             command.ExecuteReader();
767             command.Connection.Close();
768             
769             
770         }
771         
772                 [Test]
773         [ExpectedException(typeof(NpgsqlException))]
774         public void InvalidConnectionString()
775         {
776             NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=npgsql_tests");
777             
778             NpgsqlCommand command = new NpgsqlCommand("select * from tablea", conn);
779             
780             command.Connection.Open();
781             command.ExecuteReader();
782             command.Connection.Close();
783             
784             
785         }
786         
787         
788         [Test]
789         public void AmbiguousFunctionParameterType()
790         {
791             NpgsqlConnection conn = new NpgsqlConnection("Server=127.0.0.1;User Id=npgsql_tests;Password=npgsql_tests");
792             
793             
794             NpgsqlCommand command = new NpgsqlCommand("ambiguousParameterType(:a, :b, :c, :d, :e, :f)", conn);
795             command.CommandType = CommandType.StoredProcedure;
796             NpgsqlParameter p = new NpgsqlParameter("a", DbType.Int16);
797             p.Value = 2;
798             command.Parameters.Add(p);
799             p = new NpgsqlParameter("b", DbType.Int32);
800             p.Value = 2;
801             command.Parameters.Add(p);
802             p = new NpgsqlParameter("c", DbType.Int64);
803             p.Value = 2;
804             command.Parameters.Add(p);
805             p = new NpgsqlParameter("d", DbType.String);
806             p.Value = "a";
807             command.Parameters.Add(p);
808             p = new NpgsqlParameter("e", DbType.String);
809             p.Value = "a";
810             command.Parameters.Add(p);
811             p = new NpgsqlParameter("f", DbType.String);
812             p.Value = "a";
813             command.Parameters.Add(p);
814             
815             
816             command.Connection.Open();
817             command.Prepare();
818             command.ExecuteScalar();
819             command.Connection.Close();
820             
821             
822         }
823         
824                 
825         }
826 }