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
33 using System.Data.Common;
34 using System.Data.Odbc;
36 using NUnit.Framework;
38 namespace MonoTests.System.Data.Connected.Odbc
42 public class OdbcCommandBuilderTest
45 public void GetInsertCommandTest ()
47 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
48 OdbcCommand cmd = null;
51 string selectQuery = "select id, lname from employee where id = 3";
52 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
53 DataSet ds = new DataSet ();
54 da.Fill (ds, "IntTest");
55 Assert.AreEqual (1, ds.Tables.Count);
57 OdbcCommandBuilder cb;
59 cb = new OdbcCommandBuilder (da);
60 cmd = cb.GetInsertCommand ();
61 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
62 cmd.CommandText, "#A1");
63 Assert.AreSame (conn, cmd.Connection, "#A2");
64 AssertInsertParameters (cmd, "#A3:");
66 cb = new OdbcCommandBuilder (da);
67 cb.QuotePrefix = "\"";
69 cmd = cb.GetInsertCommand ();
70 Assert.AreEqual ("INSERT INTO \"employee (\"id, \"lname) VALUES (?, ?)",
71 cmd.CommandText, "#B1");
72 Assert.AreSame (conn, cmd.Connection, "#B2");
73 AssertInsertParameters (cmd, "#B3:");
75 cb = new OdbcCommandBuilder (da);
78 cmd = cb.GetInsertCommand ();
79 Assert.AreEqual ("INSERT INTO employee´ (id´, lname´) VALUES (?, ?)",
80 cmd.CommandText, "#C1");
81 Assert.AreSame (conn, cmd.Connection, "#C2");
82 AssertInsertParameters (cmd, "#C3:");
84 cb = new OdbcCommandBuilder (da);
85 cb.QuotePrefix = "\"";
88 cmd = cb.GetInsertCommand ();
89 Assert.AreEqual ("INSERT INTO \"employee´ (\"id´, \"lname´) VALUES (?, ?)",
90 cmd.CommandText, "#D1");
91 Assert.AreSame (conn, cmd.Connection, "#D2");
92 AssertInsertParameters (cmd, "#D3:");
96 ConnectionManager.Instance.Odbc.CloseConnection ();
101 public void GetInsertCommandTestWithExpression ()
103 if (ConnectionManager.Instance.Odbc.EngineConfig.Type == EngineType.MySQL)
104 Assert.Ignore ("Schema info from MySQL is incomplete");
106 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
107 OdbcCommand cmd = null;
110 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
111 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
112 DataSet ds = new DataSet ();
113 da.Fill (ds, "IntTest");
114 Assert.AreEqual (1, ds.Tables.Count);
116 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
117 cmd = cb.GetInsertCommand ();
118 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
119 cmd.CommandText, "#1");
120 Assert.AreSame (conn, cmd.Connection, "#2");
121 AssertInsertParameters (cmd, "#3:");
125 ConnectionManager.Instance.Odbc.CloseConnection ();
130 public void GetUpdateCommandTest ()
132 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
133 OdbcCommand cmd = null;
136 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
137 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
138 DataSet ds = new DataSet ();
139 da.Fill (ds, "IntTest");
140 Assert.AreEqual (1, ds.Tables.Count);
142 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
143 cmd = cb.GetUpdateCommand ();
144 Assert.AreEqual ("UPDATE employee SET id = ?, lname = ? WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
145 cmd.CommandText, "#A1");
146 Assert.AreSame (conn, cmd.Connection, "#A2");
147 AssertUpdateParameters (cmd, "#A3:");
149 cb = new OdbcCommandBuilder (da);
150 cb.QuotePrefix = "\"";
152 cmd = cb.GetUpdateCommand ();
153 Assert.AreEqual ("UPDATE \"employee SET \"id = ?, \"lname = ? WHERE ((\"id = ?) AND ((? = 1 AND \"lname IS NULL) OR (\"lname = ?)))",
154 cmd.CommandText, "#B1");
155 Assert.AreSame (conn, cmd.Connection, "#B2");
156 AssertUpdateParameters (cmd, "#B3:");
158 cb = new OdbcCommandBuilder (da);
159 cb.QuoteSuffix = "´";
161 cmd = cb.GetUpdateCommand ();
162 Assert.AreEqual ("UPDATE employee´ SET id´ = ?, lname´ = ? WHERE ((id´ = ?) AND ((? = 1 AND lname´ IS NULL) OR (lname´ = ?)))",
163 cmd.CommandText, "#C1");
164 Assert.AreSame (conn, cmd.Connection, "#C2");
165 AssertUpdateParameters (cmd, "#C3:");
167 cb = new OdbcCommandBuilder (da);
168 cb.QuotePrefix = "\"";
169 cb.QuoteSuffix = "´";
171 cmd = cb.GetUpdateCommand ();
172 Assert.AreEqual ("UPDATE \"employee´ SET \"id´ = ?, \"lname´ = ? WHERE ((\"id´ = ?) AND ((? = 1 AND \"lname´ IS NULL) OR (\"lname´ = ?)))",
173 cmd.CommandText, "#D1");
174 Assert.AreSame (conn, cmd.Connection, "#D2");
175 AssertUpdateParameters (cmd, "#D3:");
179 ConnectionManager.Instance.Odbc.CloseConnection ();
184 [Ignore ("FIXME: Auto SQL generation during Update requires a valid SelectCommand")]
185 public void GetUpdateCommandDBConcurrencyExceptionTest ()
187 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
189 string selectQuery = "select id, lname from employee where id = 3";
190 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
191 DataSet ds = new DataSet ();
192 da.Fill (ds, "IntTest");
193 Assert.AreEqual (1, ds.Tables.Count);
195 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
196 Assert.IsNotNull (cb);
198 DataRow [] rows = ds.Tables [0].Select ("id=1");
199 rows [0] [0] = 6660; // non existent
200 ds.Tables [0].AcceptChanges (); // moves 6660 to original value
201 rows [0] [0] = 1; // moves 6660 as search key into db table
206 } catch (DBConcurrencyException ex) {
207 // Concurrency violation: the UpdateCommand
208 // affected 0 records
209 Assert.AreEqual (typeof (DBConcurrencyException), ex.GetType (), "#2");
210 Assert.IsNull (ex.InnerException, "#3");
211 Assert.IsNotNull (ex.Message, "#4");
212 Assert.AreSame (rows [0], ex.Row, "#5");
213 Assert.AreEqual (1, ex.RowCount, "#6");
216 ConnectionManager.Instance.Odbc.CloseConnection ();
221 [Category("NotWorking")]
222 public void GetInsertCommandTest_option_true ()
224 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
226 string selectQuery = "select id, lname from employee where id = 3";
227 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
228 DataSet ds = new DataSet ();
229 da.Fill (ds, "IntTest");
230 Assert.AreEqual (1, ds.Tables.Count);
232 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
233 OdbcCommand cmd = cb.GetInsertCommand (true);
234 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
235 cmd.CommandText, "#1");
236 Assert.AreSame (conn, cmd.Connection, "#2");
237 AssertInsertParameters (cmd, "#3:");
239 ConnectionManager.Instance.Odbc.CloseConnection ();
244 public void GetInsertCommandTest_option_false ()
246 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
248 string selectQuery = "select id, lname from employee where id = 3";
249 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
250 DataSet ds = new DataSet ();
251 da.Fill (ds, "IntTest");
252 Assert.AreEqual (1, ds.Tables.Count);
254 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
255 OdbcCommand cmd = cb.GetInsertCommand (false);
256 Assert.AreEqual ("INSERT INTO employee (id, lname) VALUES (?, ?)",
257 cmd.CommandText, "#1");
258 Assert.AreSame (conn, cmd.Connection, "#2");
259 AssertInsertParameters (cmd, "#3:");
261 ConnectionManager.Instance.Odbc.CloseConnection ();
266 [Category("NotWorking")]
267 public void GetUpdateCommandTest_option_true ()
269 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
271 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
272 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
273 DataSet ds = new DataSet ();
274 da.Fill (ds, "IntTest");
275 Assert.AreEqual (1, ds.Tables.Count);
277 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
278 OdbcCommand cmd = cb.GetUpdateCommand (true);
279 Assert.AreEqual ("UPDATE employee SET id = ?, lname = ? WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
280 cmd.CommandText, "#1");
281 Assert.AreSame (conn, cmd.Connection, "#2");
282 AssertUpdateParameters (cmd, "#3:");
284 ConnectionManager.Instance.Odbc.CloseConnection ();
289 public void GetUpdateCommandTest_option_false ()
291 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
293 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
294 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
295 DataSet ds = new DataSet ();
296 da.Fill (ds, "IntTest");
297 Assert.AreEqual (1, ds.Tables.Count);
299 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
300 OdbcCommand cmd = cb.GetUpdateCommand (false);
301 Assert.AreEqual ("UPDATE employee SET id = ?, lname = ? WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
302 cmd.CommandText, "#1");
303 Assert.AreSame (conn, cmd.Connection, "#2");
304 AssertUpdateParameters (cmd, "#3:");
306 ConnectionManager.Instance.Odbc.CloseConnection ();
311 [Category("NotWorking")]
312 public void GetDeleteCommandTest_option_true ()
314 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
316 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
317 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
318 DataSet ds = new DataSet ();
319 da.Fill (ds, "IntTest");
320 Assert.AreEqual (1, ds.Tables.Count);
322 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
323 OdbcCommand cmd = cb.GetDeleteCommand (true);
324 Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
325 cmd.CommandText, "#1");
326 Assert.AreSame (conn, cmd.Connection, "#2");
327 AssertDeleteParameters (cmd, "#3:");
329 ConnectionManager.Instance.Odbc.CloseConnection ();
334 public void GetDeleteCommandTest_option_false ()
336 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
338 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
339 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
340 DataSet ds = new DataSet ();
341 da.Fill (ds, "IntTest");
342 Assert.AreEqual (1, ds.Tables.Count);
344 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
345 OdbcCommand cmd = cb.GetDeleteCommand (false);
346 Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
347 cmd.CommandText, "#1");
348 Assert.AreSame (conn, cmd.Connection, "#2");
349 AssertDeleteParameters (cmd, "#3:");
351 ConnectionManager.Instance.Odbc.CloseConnection ();
356 public void GetDeleteCommandTest ()
358 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
359 OdbcCommand cmd = null;
362 string selectQuery = "select id, lname, id+1 as next_id from employee where id = 3";
363 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
364 DataSet ds = new DataSet ();
365 da.Fill (ds, "IntTest");
366 Assert.AreEqual (1, ds.Tables.Count);
368 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
369 cmd = cb.GetDeleteCommand ();
371 Assert.AreEqual ("DELETE FROM employee WHERE ((id = ?) AND ((? = 1 AND lname IS NULL) OR (lname = ?)))",
372 cmd.CommandText, "#A1");
373 Assert.AreSame (conn, cmd.Connection, "#A2");
374 AssertDeleteParameters (cmd, "#A3:");
376 cb = new OdbcCommandBuilder (da);
377 cb.QuotePrefix = "\"";
379 cmd = cb.GetDeleteCommand ();
380 Assert.AreEqual ("DELETE FROM \"employee WHERE ((\"id = ?) AND ((? = 1 AND \"lname IS NULL) OR (\"lname = ?)))",
381 cmd.CommandText, "#B1");
382 Assert.AreSame (conn, cmd.Connection, "#B2");
383 AssertDeleteParameters (cmd, "#B3:");
385 cb = new OdbcCommandBuilder (da);
386 cb.QuoteSuffix = "´";
388 cmd = cb.GetDeleteCommand ();
389 Assert.AreEqual ("DELETE FROM employee´ WHERE ((id´ = ?) AND ((? = 1 AND lname´ IS NULL) OR (lname´ = ?)))",
390 cmd.CommandText, "#C1");
391 Assert.AreSame (conn, cmd.Connection, "#C2");
392 AssertDeleteParameters (cmd, "#C3:");
394 cb = new OdbcCommandBuilder (da);
395 cb.QuotePrefix = "\"";
396 cb.QuoteSuffix = "´";
398 cmd = cb.GetDeleteCommand ();
399 Assert.AreEqual ("DELETE FROM \"employee´ WHERE ((\"id´ = ?) AND ((? = 1 AND \"lname´ IS NULL) OR (\"lname´ = ?)))",
400 cmd.CommandText, "#D1");
401 Assert.AreSame (conn, cmd.Connection, "#D2");
402 AssertDeleteParameters (cmd, "#D3:");
406 ConnectionManager.Instance.Odbc.CloseConnection ();
411 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
412 public void QuotePrefix_DeleteCommand_Generated ()
414 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
416 OdbcCommand cmd = null;
419 string selectQuery = "select id, lname from employee where id = 3";
420 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
421 DataSet ds = new DataSet ();
422 da.Fill (ds, "IntTest");
424 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
425 cmd = cb.GetDeleteCommand ();
426 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
430 } catch (InvalidOperationException ex) {
431 // The QuotePrefix and QuoteSuffix properties
432 // cannot be changed once an Insert, Update, or
433 // Delete command has been generated
434 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
435 Assert.IsNull (ex.InnerException, "#4");
436 Assert.IsNotNull (ex.Message, "#5");
438 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
444 ConnectionManager.Instance.Odbc.CloseConnection ();
449 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
450 public void QuotePrefix_InsertCommand_Generated ()
452 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
454 OdbcCommand cmd = null;
457 string selectQuery = "select id, lname from employee where id = 3";
458 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
459 DataSet ds = new DataSet ();
460 da.Fill (ds, "IntTest");
462 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
463 cmd = cb.GetInsertCommand ();
464 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
468 } catch (InvalidOperationException ex) {
469 // The QuotePrefix and QuoteSuffix properties
470 // cannot be changed once an Insert, Update, or
471 // Delete command has been generated
472 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
473 Assert.IsNull (ex.InnerException, "#4");
474 Assert.IsNotNull (ex.Message, "#5");
476 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
482 ConnectionManager.Instance.Odbc.CloseConnection ();
487 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
488 public void QuotePrefix_UpdateCommand_Generated ()
490 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
492 OdbcCommand cmd = null;
495 string selectQuery = "select id, lname from employee where id = 3";
496 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
497 DataSet ds = new DataSet ();
498 da.Fill (ds, "IntTest");
500 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
501 cmd = cb.GetUpdateCommand ();
502 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#1");
506 } catch (InvalidOperationException ex) {
507 // The QuotePrefix and QuoteSuffix properties
508 // cannot be changed once an Insert, Update, or
509 // Delete command has been generated
510 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
511 Assert.IsNull (ex.InnerException, "#4");
512 Assert.IsNotNull (ex.Message, "#5");
514 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
520 ConnectionManager.Instance.Odbc.CloseConnection ();
525 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
526 public void QuoteSuffix_DeleteCommand_Generated ()
528 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
530 OdbcCommand cmd = null;
533 string selectQuery = "select id, lname from employee where id = 3";
534 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
535 DataSet ds = new DataSet ();
536 da.Fill (ds, "IntTest");
538 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
539 cmd = cb.GetDeleteCommand ();
540 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
544 } catch (InvalidOperationException ex) {
545 // The QuotePrefix and QuoteSuffix properties
546 // cannot be changed once an Insert, Update, or
547 // Delete command has been generated
548 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
549 Assert.IsNull (ex.InnerException, "#4");
550 Assert.IsNotNull (ex.Message, "#5");
552 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#6");
558 ConnectionManager.Instance.Odbc.CloseConnection ();
563 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
564 public void QuoteSuffix_InsertCommand_Generated ()
566 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
568 OdbcCommand cmd = null;
571 string selectQuery = "select id, lname from employee where id = 3";
572 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
573 DataSet ds = new DataSet ();
574 da.Fill (ds, "IntTest");
576 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
577 cmd = cb.GetInsertCommand ();
578 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
582 } catch (InvalidOperationException ex) {
583 // The QuotePrefix and QuoteSuffix properties
584 // cannot be changed once an Insert, Update, or
585 // Delete command has been generated
586 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
587 Assert.IsNull (ex.InnerException, "#4");
588 Assert.IsNotNull (ex.Message, "#5");
590 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#6");
596 ConnectionManager.Instance.Odbc.CloseConnection ();
601 [Ignore ("QuoteSuffix and QuotePrefix are now in DbCommandBuilder, while commands are in implementation classes. Result: we cannot perform this check until we refactor this.")]
602 public void QuoteSuffix_UpdateCommand_Generated ()
604 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
606 OdbcCommand cmd = null;
609 string selectQuery = "select id, lname from employee where id = 3";
610 OdbcDataAdapter da = new OdbcDataAdapter (selectQuery, conn);
611 DataSet ds = new DataSet ();
612 da.Fill (ds, "IntTest");
614 OdbcCommandBuilder cb = new OdbcCommandBuilder (da);
615 cmd = cb.GetUpdateCommand ();
616 Assert.AreEqual (string.Empty, cb.QuoteSuffix, "#1");
620 } catch (InvalidOperationException ex) {
621 // The QuotePrefix and QuoteSuffix properties
622 // cannot be changed once an Insert, Update, or
623 // Delete command has been generated
624 Assert.AreEqual (typeof (InvalidOperationException), ex.GetType (), "#3");
625 Assert.IsNull (ex.InnerException, "#4");
626 Assert.IsNotNull (ex.Message, "#5");
628 Assert.AreEqual (string.Empty, cb.QuotePrefix, "#6");
634 ConnectionManager.Instance.Odbc.CloseConnection ();
638 [Test] // QuoteIdentifier (String, OdbcConnection)
639 public void QuoteIdentifier2 ()
641 OdbcCommandBuilder cb;
642 OdbcConnection conn = ConnectionManager.Instance.Odbc.Connection;
644 string quote_char = ConnectionManager.Instance.Odbc.EngineConfig.QuoteCharacter;
647 cb = new OdbcCommandBuilder ();
648 Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A1");
649 Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A2");
650 Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A3");
651 Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A4");
652 Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A5");
653 Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A6");
654 cb.QuoteSuffix = "def";
655 Assert.AreEqual (quote_char + "mono" + quote_char, cb.QuoteIdentifier ("mono", conn), "#A7");
656 Assert.AreEqual (quote_char + "Z" + quote_char, cb.QuoteIdentifier ("Z", conn), "#A8");
657 Assert.AreEqual (quote_char + "abc" + quote_char, cb.QuoteIdentifier ("abc", conn), "#A9");
658 Assert.AreEqual (quote_char + quote_char, cb.QuoteIdentifier (string.Empty, conn), "#A10");
659 Assert.AreEqual (quote_char + " " + quote_char, cb.QuoteIdentifier (" ", conn), "#A11");
660 Assert.AreEqual (quote_char + "\r" + quote_char, cb.QuoteIdentifier ("\r", conn), "#A12");
662 cb = new OdbcCommandBuilder ();
663 cb.QuotePrefix = "abc";
664 Assert.AreEqual ("abcmono", cb.QuoteIdentifier ("mono", conn), "#B1");
665 Assert.AreEqual ("abcZ", cb.QuoteIdentifier ("Z", conn), "#B2");
666 Assert.AreEqual ("abcabc", cb.QuoteIdentifier ("abc", conn), "#B3");
667 Assert.AreEqual ("abc", cb.QuoteIdentifier (string.Empty, conn), "#B4");
668 Assert.AreEqual ("abc ", cb.QuoteIdentifier (" ", conn), "#B5");
669 Assert.AreEqual ("abc\r", cb.QuoteIdentifier ("\r", conn), "#B6");
670 cb.QuoteSuffix = "def";
671 Assert.AreEqual ("abcmonodef", cb.QuoteIdentifier ("mono", conn), "#B7");
672 Assert.AreEqual ("abcZdef", cb.QuoteIdentifier ("Z", conn), "#B8");
673 Assert.AreEqual ("abcabcdef", cb.QuoteIdentifier ("abc", conn), "#B9");
674 Assert.AreEqual ("abcdef", cb.QuoteIdentifier (string.Empty, conn), "#B10");
675 Assert.AreEqual ("abc def", cb.QuoteIdentifier (" ", conn), "#B11");
676 Assert.AreEqual ("abc\rdef", cb.QuoteIdentifier ("\r", conn), "#B12");
678 cb.QuotePrefix = string.Empty;
680 cb = new OdbcCommandBuilder ();
681 cb.QuotePrefix = "X";
682 Assert.AreEqual ("Xmono", cb.QuoteIdentifier ("mono", conn), "#D1");
683 Assert.AreEqual ("XZ", cb.QuoteIdentifier ("Z", conn), "#D2");
684 Assert.AreEqual ("XX", cb.QuoteIdentifier ("X", conn), "#D3");
685 Assert.AreEqual ("X", cb.QuoteIdentifier (string.Empty, conn), "#D4");
686 Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D5");
687 Assert.AreEqual ("X\r", cb.QuoteIdentifier ("\r", conn), "#D6");
688 cb.QuoteSuffix = " ";
689 Assert.AreEqual ("Xmono ", cb.QuoteIdentifier ("mono", conn), "#D7");
690 Assert.AreEqual ("XZ ", cb.QuoteIdentifier ("Z", conn), "#D8");
691 Assert.AreEqual ("XX ", cb.QuoteIdentifier ("X", conn), "#D9");
692 Assert.AreEqual ("X ", cb.QuoteIdentifier (string.Empty, conn), "#D10");
693 Assert.AreEqual ("X ", cb.QuoteIdentifier (" ", conn), "#D11");
694 Assert.AreEqual ("X\r ", cb.QuoteIdentifier ("\r", conn), "#D12");
696 cb = new OdbcCommandBuilder ();
697 cb.QuotePrefix = " ";
698 Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E1");
699 Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E2");
700 Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E3");
701 Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E4");
702 Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E5");
703 Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E6");
704 cb.QuoteSuffix = "def";
705 Assert.AreEqual ("mono", cb.QuoteIdentifier ("mono", conn), "#E7");
706 Assert.AreEqual ("Z", cb.QuoteIdentifier ("Z", conn), "#E8");
707 Assert.AreEqual ("abc", cb.QuoteIdentifier ("abc", conn), "#E9");
708 Assert.AreEqual (string.Empty, cb.QuoteIdentifier (string.Empty, conn), "#E10");
709 Assert.AreEqual (" ", cb.QuoteIdentifier (" ", conn), "#E11");
710 Assert.AreEqual ("\r", cb.QuoteIdentifier ("\r", conn), "#E12");
712 ConnectionManager.Instance.Odbc.CloseConnection ();
716 void AssertInsertParameters (OdbcCommand cmd, string prefix)
718 Assert.AreEqual (2, cmd.Parameters.Count, prefix + "Count");
719 Assert.AreEqual (DbType.Int32, cmd.Parameters [0].DbType, prefix + "DbType (0)");
720 Assert.AreEqual ("p1", cmd.Parameters [0].ParameterName, prefix + "ParameterName (0)");
721 Assert.AreEqual ("id", cmd.Parameters [0].SourceColumn, prefix + "SourceColumn (0)");
722 Assert.IsNull (cmd.Parameters [0].Value, prefix + "Value (0)");
723 Assert.AreEqual (DbType.String, cmd.Parameters [1].DbType, prefix + "DbType (1)");
724 Assert.AreEqual ("p2", cmd.Parameters [1].ParameterName, prefix + "ParameterName (1)");
725 Assert.AreEqual ("lname", cmd.Parameters [1].SourceColumn, prefix + "SourceColumn (1)");
726 Assert.IsNull (cmd.Parameters [1].Value, prefix + "Value (1)");
729 void AssertUpdateParameters (OdbcCommand cmd, string prefix)
731 Assert.AreEqual (5, cmd.Parameters.Count, prefix + "Count");
732 Assert.AreEqual (DbType.Int32, cmd.Parameters [0].DbType, prefix + "DbType (0)");
733 Assert.AreEqual ("p1", cmd.Parameters [0].ParameterName, prefix + "ParameterName (0)");
734 Assert.AreEqual ("id", cmd.Parameters [0].SourceColumn, prefix + "SourceColumn (0)");
735 Assert.IsNull (cmd.Parameters [0].Value, prefix + "Value (0)");
736 Assert.AreEqual (DbType.String, cmd.Parameters [1].DbType, prefix + "DbType (1)");
737 Assert.AreEqual ("p2", cmd.Parameters [1].ParameterName, prefix + "ParameterName (1)");
738 Assert.AreEqual ("lname", cmd.Parameters [1].SourceColumn, prefix + "SourceColumn (1)");
739 Assert.IsNull (cmd.Parameters [1].Value, prefix + "Value (1)");
740 Assert.AreEqual (DbType.Int32, cmd.Parameters [2].DbType, prefix + "DbType (2)");
741 Assert.AreEqual ("p3", cmd.Parameters [2].ParameterName, prefix + "ParameterName (2)");
742 Assert.AreEqual ("id", cmd.Parameters [2].SourceColumn, prefix + "SourceColumn (2)");
743 Assert.IsNull (cmd.Parameters [2].Value, prefix + "Value (2)");
744 Assert.AreEqual (DbType.Int32, cmd.Parameters [3].DbType, prefix + "DbType (3)");
745 Assert.AreEqual ("p4", cmd.Parameters [3].ParameterName, prefix + "ParameterName (3)");
746 Assert.AreEqual ("lname", cmd.Parameters [3].SourceColumn, prefix + "SourceColumn (3)");
747 Assert.AreEqual (1, cmd.Parameters [3].Value, prefix + "Value (3)");
748 Assert.AreEqual (DbType.String, cmd.Parameters [4].DbType, prefix + "DbType (4)");
749 Assert.AreEqual ("p5", cmd.Parameters [4].ParameterName, prefix + "ParameterName (4)");
750 Assert.AreEqual ("lname", cmd.Parameters [4].SourceColumn, prefix + "SourceColumn (4)");
751 Assert.IsNull (cmd.Parameters [4].Value, prefix + "Value (4)");
754 void AssertDeleteParameters (OdbcCommand cmd, string prefix)
756 Assert.AreEqual (3, cmd.Parameters.Count, prefix + "Count");
757 Assert.AreEqual (DbType.Int32, cmd.Parameters [0].DbType, prefix + "DbType (0)");
758 Assert.AreEqual ("p1", cmd.Parameters [0].ParameterName, prefix + "ParameterName (0)");
759 Assert.AreEqual ("id", cmd.Parameters [0].SourceColumn, prefix + "SourceColumn (0)");
760 Assert.IsNull (cmd.Parameters [0].Value, prefix + "Value (0)");
761 Assert.AreEqual (DbType.Int32, cmd.Parameters [1].DbType, prefix + "DbType (1)");
762 Assert.AreEqual ("p2", cmd.Parameters [1].ParameterName, prefix + "ParameterName (1)");
763 Assert.AreEqual ("lname", cmd.Parameters [1].SourceColumn, prefix + "SourceColumn (1)");
764 Assert.AreEqual (1, cmd.Parameters [1].Value, prefix + "Value (1)");
765 Assert.AreEqual (DbType.String, cmd.Parameters [2].DbType, prefix + "DbType (2)");
766 Assert.AreEqual ("p3", cmd.Parameters [2].ParameterName, prefix + "ParameterName (2)");
767 Assert.AreEqual ("lname", cmd.Parameters [2].SourceColumn, prefix + "SourceColumn (2)");
768 Assert.IsNull (cmd.Parameters [2].Value, prefix + "Value (2)");
771 // FIXME: test SetAllValues
772 // FIXME: Add tests for examining RowError
773 // FIXME: Add test for ContinueUpdateOnError property