| ... | ... |
@@ -15,6 +15,8 @@ use DBIx::Custom; |
| 15 | 15 |
sub password { 'dbix_custom' }
|
| 16 | 16 |
|
| 17 | 17 |
sub create_table1 { 'create table table1 (key1 varchar(255), key2 varchar(255));' }
|
| 18 |
+ sub create_table1_2 {'create table table1 (key1 varchar(255), key2 varchar(255), '
|
|
| 19 |
+ . 'key3 varchar(255), key4 varchar(255), key5 varchar(255));' } |
|
| 18 | 20 |
} |
| 19 | 21 |
|
| 20 | 22 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -15,6 +15,8 @@ use DBIx::Custom; |
| 15 | 15 |
sub password { 'dbix_custom' }
|
| 16 | 16 |
|
| 17 | 17 |
sub create_table1 { 'create table table1 (key1 varchar(255), key2 varchar(255));' }
|
| 18 |
+ sub create_table1_2 {'create table table1 (key1 varchar(255), key2 varchar(255), '
|
|
| 19 |
+ . 'key3 varchar(255), key4 varchar(255), key5 varchar(255));' } |
|
| 18 | 20 |
} |
| 19 | 21 |
|
| 20 | 22 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -11,6 +11,7 @@ use DBIx::Custom; |
| 11 | 11 |
sub dsn { 'dbi:SQLite:dbname=:memory:' }
|
| 12 | 12 |
sub quote { '""' }
|
| 13 | 13 |
sub create_table1 { 'create table table1 (key1, key2);' }
|
| 14 |
+ sub create_table1_2 {'create table table1 (key1, key2, key3, key4, key5);' }
|
|
| 14 | 15 |
} |
| 15 | 16 |
|
| 16 | 17 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -10,6 +10,7 @@ use DBIx::Custom; |
| 10 | 10 |
no warnings 'redefine'; |
| 11 | 11 |
sub dsn { 'dbi:SQLite:dbname=:memory:' }
|
| 12 | 12 |
sub create_table1 { 'create table table1 (key1, key2);' }
|
| 13 |
+ sub create_table1_2 {'create table table1 (key1, key2, key3, key4, key5);' }
|
|
| 13 | 14 |
} |
| 14 | 15 |
|
| 15 | 16 |
require "$FindBin::Bin/common.t"; |
| ... | ... |
@@ -125,3 +125,63 @@ $result = $dbi->execute($select_query, param => {'table1.key1' => [1,5], 'table1
|
| 125 | 125 |
$rows = $result->all; |
| 126 | 126 |
is_deeply($rows, [{key1 => 2, key2 => 4}], "filter");
|
| 127 | 127 |
|
| 128 |
+test 'DBIx::Custom::SQLTemplate basic tag'; |
|
| 129 |
+$dbi->execute('drop table table1');
|
|
| 130 |
+$dbi->execute($dbi->create_table1_2); |
|
| 131 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 132 |
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 133 |
+ |
|
| 134 |
+$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
|
| 135 |
+$query = $dbi->execute($source, {}, query => 1);
|
|
| 136 |
+$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
|
| 137 |
+$rows = $result->all; |
|
| 138 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
|
|
| 139 |
+ |
|
| 140 |
+$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
|
| 141 |
+$query = $dbi->execute($source, {}, query => 1);
|
|
| 142 |
+$result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
|
| 143 |
+$rows = $result->all; |
|
| 144 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
|
|
| 145 |
+ |
|
| 146 |
+$source = "select * from table1 where {<= key1} and {like key2};";
|
|
| 147 |
+$query = $dbi->execute($source, {}, query => 1);
|
|
| 148 |
+$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
|
|
| 149 |
+$rows = $result->all; |
|
| 150 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2");
|
|
| 151 |
+ |
|
| 152 |
+test 'DIB::Custom::SQLTemplate in tag'; |
|
| 153 |
+$dbi->execute('drop table table1');
|
|
| 154 |
+$dbi->execute($dbi->create_table1_2); |
|
| 155 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 156 |
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 157 |
+ |
|
| 158 |
+$source = "select * from table1 where {in key1 2};";
|
|
| 159 |
+$query = $dbi->execute($source, {}, query => 1);
|
|
| 160 |
+$result = $dbi->execute($query, param => {key1 => [9, 1]});
|
|
| 161 |
+$rows = $result->all; |
|
| 162 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
|
|
| 163 |
+ |
|
| 164 |
+test 'DBIx::Custom::SQLTemplate insert tag'; |
|
| 165 |
+$dbi->delete_all(table => 'table1'); |
|
| 166 |
+$insert_source = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
|
|
| 167 |
+$dbi->execute($insert_source, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 168 |
+ |
|
| 169 |
+$result = $dbi->execute('select * from table1;');
|
|
| 170 |
+$rows = $result->all; |
|
| 171 |
+is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
|
|
| 172 |
+ |
|
| 173 |
+test 'DBIx::Custom::SQLTemplate update tag'; |
|
| 174 |
+$dbi->delete_all(table => 'table1'); |
|
| 175 |
+$insert_source = "insert into table1 {insert_param key1 key2 key3 key4 key5}";
|
|
| 176 |
+$dbi->execute($insert_source, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 177 |
+$dbi->execute($insert_source, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 178 |
+ |
|
| 179 |
+$update_source = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
|
|
| 180 |
+$dbi->execute($update_source, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
|
|
| 181 |
+ |
|
| 182 |
+$result = $dbi->execute('select * from table1 order by key1;');
|
|
| 183 |
+$rows = $result->all; |
|
| 184 |
+is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
|
|
| 185 |
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
|
|
| 186 |
+ |
|
| 187 |
+1; |
| ... | ... |
@@ -57,67 +57,8 @@ my $join; |
| 57 | 57 |
# Prepare table |
| 58 | 58 |
$dbi = DBIx::Custom->connect(%memory); |
| 59 | 59 |
|
| 60 |
-test 'DBIx::Custom::SQLTemplate basic tag'; |
|
| 61 |
-$dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
|
|
| 62 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 63 |
-$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 64 |
- |
|
| 65 |
-$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
|
| 66 |
-$query = $dbi->execute($source, {}, query => 1);
|
|
| 67 |
-$result = $dbi->execute($query, param => {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
|
| 68 |
-$rows = $result->all; |
|
| 69 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
|
|
| 70 |
- |
|
| 71 |
-$source = "select * from table1 where key1 = :key1 and {<> key2} and {< key3} and {> key4} and {>= key5};";
|
|
| 72 |
-$query = $dbi->execute($source, {}, query => 1);
|
|
| 73 |
-$result = $dbi->execute($query, {key1 => 1, key2 => 3, key3 => 4, key4 => 3, key5 => 5});
|
|
| 74 |
-$rows = $result->all; |
|
| 75 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag1");
|
|
| 76 |
- |
|
| 77 |
-$source = "select * from table1 where {<= key1} and {like key2};";
|
|
| 78 |
-$query = $dbi->execute($source, {}, query => 1);
|
|
| 79 |
-$result = $dbi->execute($query, param => {key1 => 1, key2 => '%2%'});
|
|
| 80 |
-$rows = $result->all; |
|
| 81 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic tag2");
|
|
| 82 |
- |
|
| 83 |
-test 'DIB::Custom::SQLTemplate in tag'; |
|
| 84 |
-$dbi->execute('drop table table1');
|
|
| 85 |
-$dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
|
|
| 86 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 87 |
-$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 88 |
- |
|
| 89 |
-$source = "select * from table1 where {in key1 2};";
|
|
| 90 |
-$query = $dbi->execute($source, {}, query => 1);
|
|
| 91 |
-$result = $dbi->execute($query, param => {key1 => [9, 1]});
|
|
| 92 |
-$rows = $result->all; |
|
| 93 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
|
|
| 94 |
- |
|
| 95 |
-test 'DBIx::Custom::SQLTemplate insert tag'; |
|
| 96 |
-$dbi->execute("delete from table1");
|
|
| 97 |
-$insert_source = 'insert into table1 {insert_param key1 key2 key3 key4 key5}';
|
|
| 98 |
-$dbi->execute($insert_source, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 99 |
- |
|
| 100 |
-$result = $dbi->execute('select * from table1;');
|
|
| 101 |
-$rows = $result->all; |
|
| 102 |
-is_deeply($rows, [{key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5}], "basic");
|
|
| 103 |
- |
|
| 104 |
-test 'DBIx::Custom::SQLTemplate update tag'; |
|
| 105 |
-$dbi->execute("delete from table1");
|
|
| 106 |
-$insert_source = "insert into table1 {insert_param key1 key2 key3 key4 key5}";
|
|
| 107 |
-$dbi->execute($insert_source, param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 108 |
-$dbi->execute($insert_source, param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 109 |
- |
|
| 110 |
-$update_source = 'update table1 {update_param key1 key2 key3 key4} where {= key5}';
|
|
| 111 |
-$dbi->execute($update_source, param => {key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5});
|
|
| 112 |
- |
|
| 113 |
-$result = $dbi->execute('select * from table1;');
|
|
| 114 |
-$rows = $result->all; |
|
| 115 |
-is_deeply($rows, [{key1 => 1, key2 => 1, key3 => 1, key4 => 1, key5 => 5},
|
|
| 116 |
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}], "basic");
|
|
| 117 |
- |
|
| 118 |
- |
|
| 119 | 60 |
test 'Named placeholder'; |
| 120 |
-$dbi->execute('drop table table1');
|
|
| 61 |
+#$dbi->execute('drop table table1');
|
|
| 121 | 62 |
$dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
|
| 122 | 63 |
$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
| 123 | 64 |
$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|