@@ -42,6 +42,29 @@ test(function () use ($context) { // test Selection as a parameter
4242 ]), $ sqlBuilder ->buildSelectQuery ());
4343});
4444
45+
46+ test (function () use ($ context ) { // test more Selection as a parameter
47+ $ sqlBuilder = new SqlBuilder ('book ' , $ context );
48+ $ sqlBuilder ->addWhere ('id ' , $ context ->table ('book ' ));
49+ $ sqlBuilder ->addWhere ('id ' , $ context ->table ('book_tag ' )->select ('book_id ' ));
50+ Assert::equal (reformat ([
51+ 'mysql ' => 'SELECT * FROM `book` WHERE (`id` IN (?)) AND (`id` IN (?)) ' ,
52+ 'SELECT * FROM [book] WHERE ([id] IN (SELECT [id] FROM [book])) AND ([id] IN (SELECT [book_id] FROM [book_tag])) ' ,
53+ ]), $ sqlBuilder ->buildSelectQuery ());
54+ });
55+
56+
57+ test (function () use ($ context ) { // test more ActiveRow as a parameter
58+ $ sqlBuilder = new SqlBuilder ('book ' , $ context );
59+ $ books = $ context ->table ('book ' )->where ('id ' , [1 ,2 ])->fetchPairs ('id ' );
60+ $ sqlBuilder ->addWhere ('id ? ' , $ books [1 ]);
61+ $ sqlBuilder ->addWhere ('id ? ' , $ books [2 ]);
62+ Assert::equal (reformat ([
63+ 'SELECT * FROM [book] WHERE ([id] = ?) AND ([id] = ?) ' ,
64+ ]), $ sqlBuilder ->buildSelectQuery ());
65+ });
66+
67+
4568test (function () use ($ context ) { // test Selection with parameters as a parameter
4669 $ sqlBuilder = new SqlBuilder ('book ' , $ context );
4770 $ sqlBuilder ->addWhere ('id ' , $ context ->table ('book ' )->having ('COUNT(:book_tag.tag_id) > ' , 1 ));
@@ -53,6 +76,7 @@ test(function () use ($context) { // test Selection with parameters as a paramet
5376 Assert::count (1 , $ sqlBuilder ->getParameters ());
5477});
5578
79+
5680test (function () use ($ context ) { // test Selection with column as a parameter
5781 $ sqlBuilder = new SqlBuilder ('book ' , $ context );
5882 $ sqlBuilder ->addWhere ('id ' , $ context ->table ('book ' )->select ('id ' ));
0 commit comments