1 // OdbcCommandBuilderTest.cs - NUnit Test Cases for testing the
2 // OdbcCommandBuilder Test.
5 // Sureshkumar T (tsureshkumar@novell.com)
7 // Copyright (c) 2004 Novell Inc., and the individuals listed on the
11 // Permission is hereby granted, free of charge, to any person
12 // obtaining a copy of this software and associated documentation
13 // files (the "Software"), to deal in the Software without
14 // restriction, including without limitation the rights to use, copy,
15 // modify, merge, publish, distribute, sublicense, and/or sell copies
16 // of the Software, and to permit persons to whom the Software is
17 // furnished to do so, subject to the following conditions:
19 // The above copyright notice and this permission notice shall be
20 // included in all copies or substantial portions of the Software.
22 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
23 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
24 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
25 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
26 // BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
27 // ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
28 // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35 using System.Data.Common;
36 using System.Data.Odbc;
38 using NUnit.Framework;
40 namespace MonoTests.System.Data.Connected.Odbc
44 public class OdbcCommandBuilderTest
47 public void GetInsertCommandTest ()
49 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
50 OdbcCommand cmd = null;
53 string selectQuery = "select id, lname from employee where id = 3";
54 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
55 DataSet ds = new DataSet ();
56 da.Fill (ds, "IntTest");
57 Assert.AreEqual (1, ds.Tables.Count);
59 OdbcCommandBuilder cb;
61 cb = new OdbcCommandBuilder (da);
62 cmd = cb.GetInsertCommand ();
63 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
64 cmd.CommandText, "#A1");
65 Assert.AreSame (conn, cmd.Connection, "#A2");
66 AssertInsertParameters (cmd, "#A3:");
68 cb = new OdbcCommandBuilder (da);
69 cb.QuotePrefix = "\"";
71 cmd = cb.GetInsertCommand ();
72 Assert.AreEqual ("INSERT INTO \"employee (\"id, \"lname) VALUES (?, ?)",
73 cmd.CommandText, "#B1");
74 Assert.AreSame (conn, cmd.Connection, "#B2");
75 AssertInsertParameters (cmd, "#B3:");
77 cb = new OdbcCommandBuilder (da);
80 cmd = cb.GetInsertCommand ();
81 Assert.AreEqual ("INSERT INTO employee´ (id´, lname´) VALUES (?, ?)",
82 cmd.CommandText, "#C1");
83 Assert.AreSame (conn, cmd.Connection, "#C2");
84 AssertInsertParameters (cmd, "#C3:");
86 cb = new OdbcCommandBuilder (da);
87 cb.QuotePrefix = "\"";
90 cmd = cb.GetInsertCommand ();
91 Assert.AreEqual ("INSERT INTO \"employee´ (\"id´, \"lname´) VALUES (?, ?)",
92 cmd.CommandText, "#D1");
93 Assert.AreSame (conn, cmd.Connection, "#D2");
94 AssertInsertParameters (cmd, "#D3:");
98 ConnectionManager.Instance.Odbc.CloseConnection ();
103 public void GetInsertCommandTestWithExpression ()
105 if (ConnectionManager.Instance.Odbc.EngineConfig.Type == EngineType.MySQL)
106 Assert.Ignore ("Schema info from MySQL is incomplete");
108 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
109 OdbcCommand cmd = null;
112 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
113 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
114 DataSet ds = new DataSet ();
115 da.Fill (ds, "IntTest");
116 Assert.AreEqual (1, ds.Tables.Count);
118 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
119 cmd = cb.GetInsertCommand ();
120 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
121 cmd.CommandText, "#1");
122 Assert.AreSame (conn, cmd.Connection, "#2");
123 AssertInsertParameters (cmd, "#3:");
127 ConnectionManager.Instance.Odbc.CloseConnection ();
132 public void GetUpdateCommandTest ()
134 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
135 OdbcCommand cmd = null;
138 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
139 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
140 DataSet ds = new DataSet ();
141 da.Fill (ds, "IntTest");
142 Assert.AreEqual (1, ds.Tables.Count);
144 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
145 cmd = cb.GetUpdateCommand ();
146 Assert.AreEqual ("UPDATE employee SET id = ?, lname = ? WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
147 cmd.CommandText, "#A1");
148 Assert.AreSame (conn, cmd.Connection, "#A2");
149 AssertUpdateParameters (cmd, "#A3:");
151 cb = new OdbcCommandBuilder (da);
152 cb.QuotePrefix = "\"";
154 cmd = cb.GetUpdateCommand ();
155 Assert.AreEqual ("UPDATE \"employee SET \"id = ?, \"lname = ? WHERE ((\"id = ?) AND ((? = 1 AND \"lname IS NULL) OR (\"lname = ?)))",
156 cmd.CommandText, "#B1");
157 Assert.AreSame (conn, cmd.Connection, "#B2");
158 AssertUpdateParameters (cmd, "#B3:");
160 cb = new OdbcCommandBuilder (da);
161 cb.QuoteSuffix = "´";
163 cmd = cb.GetUpdateCommand ();
164 Assert.AreEqual ("UPDATE employee´ SET id´ = ?, lname´ = ? WHERE ((id´ = ?) AND ((? = 1 AND lname´ IS NULL) OR (lname´ = ?)))",
165 cmd.CommandText, "#C1");
166 Assert.AreSame (conn, cmd.Connection, "#C2");
167 AssertUpdateParameters (cmd, "#C3:");
169 cb = new OdbcCommandBuilder (da);
170 cb.QuotePrefix = "\"";
171 cb.QuoteSuffix = "´";
173 cmd = cb.GetUpdateCommand ();
174 Assert.AreEqual ("UPDATE \"employee´ SET \"id´ = ?, \"lname´ = ? WHERE ((\"id´ = ?) AND ((? = 1 AND \"lname´ IS NULL) OR (\"lname´ = ?)))",
175 cmd.CommandText, "#D1");
176 Assert.AreSame (conn, cmd.Connection, "#D2");
177 AssertUpdateParameters (cmd, "#D3:");
181 ConnectionManager.Instance.Odbc.CloseConnection ();
186 [Ignore ("FIXME: Auto SQL generation during Update requires a valid SelectCommand")]
187 public void GetUpdateCommandDBConcurrencyExceptionTest ()
189 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
191 string selectQuery = "select id, lname from employee where id = 3";
192 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
193 DataSet ds = new DataSet ();
194 da.Fill (ds, "IntTest");
195 Assert.AreEqual (1, ds.Tables.Count);
197 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
198 Assert.IsNotNull (cb);
200 DataRow [] rows = ds.Tables [0].Select ("id=1");
201 rows [0] [0] = 6660; // non existent
202 ds.Tables [0].AcceptChanges (); // moves 6660 to original value
203 rows [0] [0] = 1; // moves 6660 as search key into db table
208 } catch (DBConcurrencyException ex) {
209 // Concurrency violation: the UpdateCommand
210 // affected 0 records
211 Assert.AreEqual (typeof (DBConcurrencyException), ex.GetType (), "#2");
212 Assert.IsNull (ex.InnerException, "#3");
213 Assert.IsNotNull (ex.Message, "#4");
214 Assert.AreSame (rows [0], ex.Row, "#5");
215 Assert.AreEqual (1, ex.RowCount, "#6");
218 ConnectionManager.Instance.Odbc.CloseConnection ();
223 [Category("NotWorking")]
224 public void GetInsertCommandTest_option_true ()
226 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
228 string selectQuery = "select id, lname from employee where id = 3";
229 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
230 DataSet ds = new DataSet ();
231 da.Fill (ds, "IntTest");
232 Assert.AreEqual (1, ds.Tables.Count);
234 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
235 OdbcCommand cmd = cb.GetInsertCommand (true);
236 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
237 cmd.CommandText, "#1");
238 Assert.AreSame (conn, cmd.Connection, "#2");
239 AssertInsertParameters (cmd, "#3:");
241 ConnectionManager.Instance.Odbc.CloseConnection ();
246 public void GetInsertCommandTest_option_false ()
248 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
250 string selectQuery = "select id, lname from employee where id = 3";
251 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
252 DataSet ds = new DataSet ();
253 da.Fill (ds, "IntTest");
254 Assert.AreEqual (1, ds.Tables.Count);
256 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
257 OdbcCommand cmd = cb.GetInsertCommand (false);
258 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
259 cmd.CommandText, "#1");
260 Assert.AreSame (conn, cmd.Connection, "#2");
261 AssertInsertParameters (cmd, "#3:");
263 ConnectionManager.Instance.Odbc.CloseConnection ();
268 [Category("NotWorking")]
269 public void GetUpdateCommandTest_option_true ()
271 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
273 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
274 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
275 DataSet ds = new DataSet ();
276 da.Fill (ds, "IntTest");
277 Assert.AreEqual (1, ds.Tables.Count);
279 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
280 OdbcCommand cmd = cb.GetUpdateCommand (true);
281 Assert.AreEqual ("UPDATE employee SET id = ?, lname = ? WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
282 cmd.CommandText, "#1");
283 Assert.AreSame (conn, cmd.Connection, "#2");
284 AssertUpdateParameters (cmd, "#3:");
286 ConnectionManager.Instance.Odbc.CloseConnection ();
291 public void GetUpdateCommandTest_option_false ()
293 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
295 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
296 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
297 DataSet ds = new DataSet ();
298 da.Fill (ds, "IntTest");
299 Assert.AreEqual (1, ds.Tables.Count);
301 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
302 OdbcCommand cmd = cb.GetUpdateCommand (false);
303 Assert.AreEqual ("UPDATE employee SET id = ?, lname = ? WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
304 cmd.CommandText, "#1");
305 Assert.AreSame (conn, cmd.Connection, "#2");
306 AssertUpdateParameters (cmd, "#3:");
308 ConnectionManager.Instance.Odbc.CloseConnection ();
313 [Category("NotWorking")]
314 public void GetDeleteCommandTest_option_true ()
316 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
318 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
319 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
320 DataSet ds = new DataSet ();
321 da.Fill (ds, "IntTest");
322 Assert.AreEqual (1, ds.Tables.Count);
324 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
325 OdbcCommand cmd = cb.GetDeleteCommand (true);
326 Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
327 cmd.CommandText, "#1");
328 Assert.AreSame (conn, cmd.Connection, "#2");
329 AssertDeleteParameters (cmd, "#3:");
331 ConnectionManager.Instance.Odbc.CloseConnection ();
336 public void GetDeleteCommandTest_option_false ()
338 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
340 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
341 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
342 DataSet ds = new DataSet ();
343 da.Fill (ds, "IntTest");
344 Assert.AreEqual (1, ds.Tables.Count);
346 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
347 OdbcCommand cmd = cb.GetDeleteCommand (false);
348 Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
349 cmd.CommandText, "#1");
350 Assert.AreSame (conn, cmd.Connection, "#2");
351 AssertDeleteParameters (cmd, "#3:");
353 ConnectionManager.Instance.Odbc.CloseConnection ();
358 public void GetDeleteCommandTest ()
360 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
361 OdbcCommand cmd = null;
364 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
365 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
366 DataSet ds = new DataSet ();
367 da.Fill (ds, "IntTest");
368 Assert.AreEqual (1, ds.Tables.Count);
370 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
371 cmd = cb.GetDeleteCommand ();
373 Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
374 cmd.CommandText, "#A1");
375 Assert.AreSame (conn, cmd.Connection, "#A2");
376 AssertDeleteParameters (cmd, "#A3:");
378 cb = new OdbcCommandBuilder (da);
379 cb.QuotePrefix = "\"";
381 cmd = cb.GetDeleteCommand ();
382 Assert.AreEqual ("DELETE FROM \"employee WHERE ((\"id = ?) AND ((? = 1 AND \"lname IS NULL) OR (\"lname = ?)))",
383 cmd.CommandText, "#B1");
384 Assert.AreSame (conn, cmd.Connection, "#B2");
385 AssertDeleteParameters (cmd, "#B3:");
387 cb = new OdbcCommandBuilder (da);
388 cb.QuoteSuffix = "´";
390 cmd = cb.GetDeleteCommand ();
391 Assert.AreEqual ("DELETE FROM employee´ WHERE ((id´ = ?) AND ((? = 1 AND lname´ IS NULL) OR (lname´ = ?)))",
392 cmd.CommandText, "#C1");
393 Assert.AreSame (conn, cmd.Connection, "#C2");
394 AssertDeleteParameters (cmd, "#C3:");
396 cb = new OdbcCommandBuilder (da);
397 cb.QuotePrefix = "\"";
398 cb.QuoteSuffix = "´";
400 cmd = cb.GetDeleteCommand ();
401 Assert.AreEqual ("DELETE FROM \"employee´ WHERE ((\"id´ = ?) AND ((? = 1 AND \"lname´ IS NULL) OR (\"lname´ = ?)))",
402 cmd.CommandText, "#D1");
403 Assert.AreSame (conn, cmd.Connection, "#D2");
404 AssertDeleteParameters (cmd, "#D3:");
408 ConnectionManager.Instance.Odbc.CloseConnection ();
413 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
414 public void QuotePrefix_DeleteCommand_Generated ()
416 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
418 OdbcCommand cmd = null;
421 string selectQuery = "select id, lname from employee where id = 3";
422 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
423 DataSet ds = new DataSet ();
424 da.Fill (ds, "IntTest");
426 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
427 cmd = cb.GetDeleteCommand ();
428 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
432 } catch (InvalidOperationException ex) {
433 // The QuotePrefix and QuoteSuffix properties
434 // cannot be changed once an Insert, Update, or
435 // Delete command has been generated
436 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
437 Assert.IsNull (ex.InnerException, "#4");
438 Assert.IsNotNull (ex.Message, "#5");
440 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
446 ConnectionManager.Instance.Odbc.CloseConnection ();
451 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
452 public void QuotePrefix_InsertCommand_Generated ()
454 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
456 OdbcCommand cmd = null;
459 string selectQuery = "select id, lname from employee where id = 3";
460 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
461 DataSet ds = new DataSet ();
462 da.Fill (ds, "IntTest");
464 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
465 cmd = cb.GetInsertCommand ();
466 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
470 } catch (InvalidOperationException ex) {
471 // The QuotePrefix and QuoteSuffix properties
472 // cannot be changed once an Insert, Update, or
473 // Delete command has been generated
474 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
475 Assert.IsNull (ex.InnerException, "#4");
476 Assert.IsNotNull (ex.Message, "#5");
478 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
484 ConnectionManager.Instance.Odbc.CloseConnection ();
489 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
490 public void QuotePrefix_UpdateCommand_Generated ()
492 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
494 OdbcCommand cmd = null;
497 string selectQuery = "select id, lname from employee where id = 3";
498 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
499 DataSet ds = new DataSet ();
500 da.Fill (ds, "IntTest");
502 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
503 cmd = cb.GetUpdateCommand ();
504 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
508 } catch (InvalidOperationException ex) {
509 // The QuotePrefix and QuoteSuffix properties
510 // cannot be changed once an Insert, Update, or
511 // Delete command has been generated
512 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
513 Assert.IsNull (ex.InnerException, "#4");
514 Assert.IsNotNull (ex.Message, "#5");
516 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
522 ConnectionManager.Instance.Odbc.CloseConnection ();
527 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
528 public void QuoteSuffix_DeleteCommand_Generated ()
530 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
532 OdbcCommand cmd = null;
535 string selectQuery = "select id, lname from employee where id = 3";
536 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
537 DataSet ds = new DataSet ();
538 da.Fill (ds, "IntTest");
540 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
541 cmd = cb.GetDeleteCommand ();
542 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
546 } catch (InvalidOperationException ex) {
547 // The QuotePrefix and QuoteSuffix properties
548 // cannot be changed once an Insert, Update, or
549 // Delete command has been generated
550 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
551 Assert.IsNull (ex.InnerException, "#4");
552 Assert.IsNotNull (ex.Message, "#5");
554 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#6");
560 ConnectionManager.Instance.Odbc.CloseConnection ();
565 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
566 public void QuoteSuffix_InsertCommand_Generated ()
568 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
570 OdbcCommand cmd = null;
573 string selectQuery = "select id, lname from employee where id = 3";
574 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
575 DataSet ds = new DataSet ();
576 da.Fill (ds, "IntTest");
578 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
579 cmd = cb.GetInsertCommand ();
580 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
584 } catch (InvalidOperationException ex) {
585 // The QuotePrefix and QuoteSuffix properties
586 // cannot be changed once an Insert, Update, or
587 // Delete command has been generated
588 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
589 Assert.IsNull (ex.InnerException, "#4");
590 Assert.IsNotNull (ex.Message, "#5");
592 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#6");
598 ConnectionManager.Instance.Odbc.CloseConnection ();
603 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
604 public void QuoteSuffix_UpdateCommand_Generated ()
606 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
608 OdbcCommand cmd = null;
611 string selectQuery = "select id, lname from employee where id = 3";
612 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
613 DataSet ds = new DataSet ();
614 da.Fill (ds, "IntTest");
616 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
617 cmd = cb.GetUpdateCommand ();
618 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
622 } catch (InvalidOperationException ex) {
623 // The QuotePrefix and QuoteSuffix properties
624 // cannot be changed once an Insert, Update, or
625 // Delete command has been generated
626 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
627 Assert.IsNull (ex.InnerException, "#4");
628 Assert.IsNotNull (ex.Message, "#5");
630 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
636 ConnectionManager.Instance.Odbc.CloseConnection ();
640 [Test] // QuoteIdentifier (String, OdbcConnection)
641 public void QuoteIdentifier2 ()
643 OdbcCommandBuilder cb;
644 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
646 string quote_char = ConnectionManager.Instance.Odbc.EngineConfig.QuoteCharacter;
649 cb = new OdbcCommandBuilder ();
650 Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A1");
651 Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A2");
652 Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A3");
653 Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A4");
654 Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A5");
655 Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A6");
656 cb.QuoteSuffix = "def";
657 Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A7");
658 Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A8");
659 Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A9");
660 Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A10");
661 Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A11");
662 Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A12");
664 cb = new OdbcCommandBuilder ();
665 cb.QuotePrefix = "abc";
666 Assert.AreEqual ("abcmono", cb.QuoteIdentifier ("mono", conn), "#B1");
667 Assert.AreEqual ("abcZ", cb.QuoteIdentifier ("Z", conn), "#B2");
668 Assert.AreEqual ("abcabc", cb.QuoteIdentifier ("abc", conn), "#B3");
669 Assert.AreEqual ("abc", cb.QuoteIdentifier (string.Empty, conn), "#B4");
670 Assert.AreEqual ("abc ", cb.QuoteIdentifier (" ", conn), "#B5");
671 Assert.AreEqual ("abc\r", cb.QuoteIdentifier ("\r", conn), "#B6");
672 cb.QuoteSuffix = "def";
673 Assert.AreEqual ("abcmonodef", cb.QuoteIdentifier ("mono", conn), "#B7");
674 Assert.AreEqual ("abcZdef", cb.QuoteIdentifier ("Z", conn), "#B8");
675 Assert.AreEqual ("abcabcdef", cb.QuoteIdentifier ("abc", conn), "#B9");
676 Assert.AreEqual ("abcdef", cb.QuoteIdentifier (string.Empty, conn), "#B10");
677 Assert.AreEqual ("abc def", cb.QuoteIdentifier (" ", conn), "#B11");
678 Assert.AreEqual ("abc\rdef", cb.QuoteIdentifier ("\r", conn), "#B12");
680 cb.QuotePrefix = string.Empty;
682 cb = new OdbcCommandBuilder ();
683 cb.QuotePrefix = "X";
684 Assert.AreEqual ("Xmono", cb.QuoteIdentifier ("mono", conn), "#D1");
685 Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z", conn), "#D2");
686 Assert.AreEqual ("XX", cb.QuoteIdentifier ("X", conn), "#D3");
687 Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty, conn), "#D4");
688 Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D5");
689 Assert.AreEqual ("X\r", cb.QuoteIdentifier ("\r", conn), "#D6");
690 cb.QuoteSuffix = " ";
691 Assert.AreEqual ("Xmono ", cb.QuoteIdentifier ("mono", conn), "#D7");
692 Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z", conn), "#D8");
693 Assert.AreEqual ("XX ", cb.QuoteIdentifier ("X", conn), "#D9");
694 Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty, conn), "#D10");
695 Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D11");
696 Assert.AreEqual ("X\r ", cb.QuoteIdentifier ("\r", conn), "#D12");
698 cb = new OdbcCommandBuilder ();
699 cb.QuotePrefix = " ";
700 Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E1");
701 Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E2");
702 Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E3");
703 Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E4");
704 Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E5");
705 Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E6");
706 cb.QuoteSuffix = "def";
707 Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E7");
708 Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E8");
709 Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E9");
710 Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E10");
711 Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E11");
712 Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E12");
714 ConnectionManager.Instance.Odbc.CloseConnection ();
718 void AssertInsertParameters (OdbcCommand cmd, string prefix)
720 Assert.AreEqual (2, cmd.Parameters.Count, prefix + "Count");
721 Assert.AreEqual (DbType.Int32, cmd.Parameters [0].DbType, prefix + "DbType (0)");
722 Assert.AreEqual ("p1", cmd.Parameters [0].ParameterName, prefix + "ParameterName (0)");
723 Assert.AreEqual ("id", cmd.Parameters [0].SourceColumn, prefix + "SourceColumn (0)");
724 Assert.IsNull (cmd.Parameters [0].Value, prefix + "Value (0)");
725 Assert.AreEqual (DbType.String, cmd.Parameters [1].DbType, prefix + "DbType (1)");
726 Assert.AreEqual ("p2", cmd.Parameters [1].ParameterName, prefix + "ParameterName (1)");
727 Assert.AreEqual ("lname", cmd.Parameters [1].SourceColumn, prefix + "SourceColumn (1)");
728 Assert.IsNull (cmd.Parameters [1].Value, prefix + "Value (1)");
731 void AssertUpdateParameters (OdbcCommand cmd, string prefix)
733 Assert.AreEqual (5, cmd.Parameters.Count, prefix + "Count");
734 Assert.AreEqual (DbType.Int32, cmd.Parameters [0].DbType, prefix + "DbType (0)");
735 Assert.AreEqual ("p1", cmd.Parameters [0].ParameterName, prefix + "ParameterName (0)");
736 Assert.AreEqual ("id", cmd.Parameters [0].SourceColumn, prefix + "SourceColumn (0)");
737 Assert.IsNull (cmd.Parameters [0].Value, prefix + "Value (0)");
738 Assert.AreEqual (DbType.String, cmd.Parameters [1].DbType, prefix + "DbType (1)");
739 Assert.AreEqual ("p2", cmd.Parameters [1].ParameterName, prefix + "ParameterName (1)");
740 Assert.AreEqual ("lname", cmd.Parameters [1].SourceColumn, prefix + "SourceColumn (1)");
741 Assert.IsNull (cmd.Parameters [1].Value, prefix + "Value (1)");
742 Assert.AreEqual (DbType.Int32, cmd.Parameters [2].DbType, prefix + "DbType (2)");
743 Assert.AreEqual ("p3", cmd.Parameters [2].ParameterName, prefix + "ParameterName (2)");
744 Assert.AreEqual ("id", cmd.Parameters [2].SourceColumn, prefix + "SourceColumn (2)");
745 Assert.IsNull (cmd.Parameters [2].Value, prefix + "Value (2)");
746 Assert.AreEqual (DbType.Int32, cmd.Parameters [3].DbType, prefix + "DbType (3)");
747 Assert.AreEqual ("p4", cmd.Parameters [3].ParameterName, prefix + "ParameterName (3)");
748 Assert.AreEqual ("lname", cmd.Parameters [3].SourceColumn, prefix + "SourceColumn (3)");
749 Assert.AreEqual (1, cmd.Parameters [3].Value, prefix + "Value (3)");
750 Assert.AreEqual (DbType.String, cmd.Parameters [4].DbType, prefix + "DbType (4)");
751 Assert.AreEqual ("p5", cmd.Parameters [4].ParameterName, prefix + "ParameterName (4)");
752 Assert.AreEqual ("lname", cmd.Parameters [4].SourceColumn, prefix + "SourceColumn (4)");
753 Assert.IsNull (cmd.Parameters [4].Value, prefix + "Value (4)");
756 void AssertDeleteParameters (OdbcCommand cmd, string prefix)
758 Assert.AreEqual (3, cmd.Parameters.Count, prefix + "Count");
759 Assert.AreEqual (DbType.Int32, cmd.Parameters [0].DbType, prefix + "DbType (0)");
760 Assert.AreEqual ("p1", cmd.Parameters [0].ParameterName, prefix + "ParameterName (0)");
761 Assert.AreEqual ("id", cmd.Parameters [0].SourceColumn, prefix + "SourceColumn (0)");
762 Assert.IsNull (cmd.Parameters [0].Value, prefix + "Value (0)");
763 Assert.AreEqual (DbType.Int32, cmd.Parameters [1].DbType, prefix + "DbType (1)");
764 Assert.AreEqual ("p2", cmd.Parameters [1].ParameterName, prefix + "ParameterName (1)");
765 Assert.AreEqual ("lname", cmd.Parameters [1].SourceColumn, prefix + "SourceColumn (1)");
766 Assert.AreEqual (1, cmd.Parameters [1].Value, prefix + "Value (1)");
767 Assert.AreEqual (DbType.String, cmd.Parameters [2].DbType, prefix + "DbType (2)");
768 Assert.AreEqual ("p3", cmd.Parameters [2].ParameterName, prefix + "ParameterName (2)");
769 Assert.AreEqual ("lname", cmd.Parameters [2].SourceColumn, prefix + "SourceColumn (2)");
770 Assert.IsNull (cmd.Parameters [2].Value, prefix + "Value (2)");
773 // FIXME: test SetAllValues
774 // FIXME: Add tests for examining RowError
775 // FIXME: Add test for ContinueUpdateOnError property