| ... | ... |
@@ -2146,6 +2146,33 @@ $result = $model->select( |
| 2146 | 2146 |
is_deeply($result->one, |
| 2147 | 2147 |
{key1 => 1, key2 => 2, 'table2__key1' => 1, 'table2__key3' => 3});
|
| 2148 | 2148 |
|
| 2149 |
+test 'insert_param'; |
|
| 2150 |
+$dbi = DBIx::Custom->connect; |
|
| 2151 |
+eval { $dbi->execute('drop table table1') };
|
|
| 2152 |
+$dbi->execute($create_table1_2); |
|
| 2153 |
+$param = {key1 => 1, key2 => 2};
|
|
| 2154 |
+$insert_param = $dbi->insert_param($param); |
|
| 2155 |
+$sql = <<"EOS"; |
|
| 2156 |
+insert into table1 $insert_param |
|
| 2157 |
+EOS |
|
| 2158 |
+$dbi->execute($sql, param => $param, table => 'table1'); |
|
| 2159 |
+is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 2160 |
+is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 2161 |
+ |
|
| 2162 |
+$dbi = DBIx::Custom->connect; |
|
| 2163 |
+eval { $dbi->execute('drop table table1') };
|
|
| 2164 |
+$dbi->execute($create_table1_2); |
|
| 2165 |
+$param = {key1 => 1, key2 => 2};
|
|
| 2166 |
+$insert_param = $dbi->insert_param($param); |
|
| 2167 |
+$sql = <<"EOS"; |
|
| 2168 |
+insert into table1 $insert_param |
|
| 2169 |
+EOS |
|
| 2170 |
+$dbi->execute($sql, param => $param, table => 'table1'); |
|
| 2171 |
+is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 2172 |
+is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 2173 |
+ |
|
| 2174 |
+eval { $dbi->insert_param({";" => 1}) };
|
|
| 2175 |
+like($@, qr/not safety/); |
|
| 2149 | 2176 |
|
| 2150 | 2177 |
|
| 2151 | 2178 |
|
| ... | ... |
@@ -196,123 +196,6 @@ my $binary; |
| 196 | 196 |
# Prepare table |
| 197 | 197 |
$dbi = DBIx::Custom->connect; |
| 198 | 198 |
|
| 199 |
- |
|
| 200 |
- |
|
| 201 |
-test 'update_param'; |
|
| 202 |
-$dbi = DBIx::Custom->connect; |
|
| 203 |
-eval { $dbi->execute('drop table table1') };
|
|
| 204 |
-$dbi->execute($create_table1_2); |
|
| 205 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 206 |
-$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 207 |
- |
|
| 208 |
-$param = {key2 => 11};
|
|
| 209 |
-$update_param = $dbi->update_param($param); |
|
| 210 |
-$sql = <<"EOS"; |
|
| 211 |
-update table1 $update_param |
|
| 212 |
-where key1 = 1 |
|
| 213 |
-EOS |
|
| 214 |
-$dbi->execute($sql, param => $param); |
|
| 215 |
-$result = $dbi->execute('select * from table1;', table => 'table1');
|
|
| 216 |
-$rows = $result->all; |
|
| 217 |
-is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
|
| 218 |
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 219 |
- "basic"); |
|
| 220 |
- |
|
| 221 |
- |
|
| 222 |
-$dbi = DBIx::Custom->connect; |
|
| 223 |
-eval { $dbi->execute('drop table table1') };
|
|
| 224 |
-$dbi->execute($create_table1_2); |
|
| 225 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 226 |
-$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 227 |
- |
|
| 228 |
-$param = {key2 => 11, key3 => 33};
|
|
| 229 |
-$update_param = $dbi->update_param($param); |
|
| 230 |
-$sql = <<"EOS"; |
|
| 231 |
-update table1 $update_param |
|
| 232 |
-where key1 = 1 |
|
| 233 |
-EOS |
|
| 234 |
-$dbi->execute($sql, param => $param); |
|
| 235 |
-$result = $dbi->execute('select * from table1;', table => 'table1');
|
|
| 236 |
-$rows = $result->all; |
|
| 237 |
-is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
|
|
| 238 |
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 239 |
- "basic"); |
|
| 240 |
- |
|
| 241 |
-$dbi = DBIx::Custom->connect; |
|
| 242 |
-eval { $dbi->execute('drop table table1') };
|
|
| 243 |
-$dbi->execute($create_table1_2); |
|
| 244 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 245 |
-$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 246 |
- |
|
| 247 |
-$param = {key2 => 11, key3 => 33};
|
|
| 248 |
-$update_param = $dbi->update_param($param, {no_set => 1});
|
|
| 249 |
-$sql = <<"EOS"; |
|
| 250 |
-update table1 set $update_param |
|
| 251 |
-where key1 = 1 |
|
| 252 |
-EOS |
|
| 253 |
-$dbi->execute($sql, param => $param); |
|
| 254 |
-$result = $dbi->execute('select * from table1;', table => 'table1');
|
|
| 255 |
-$rows = $result->all; |
|
| 256 |
-is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
|
|
| 257 |
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 258 |
- "update param no_set"); |
|
| 259 |
- |
|
| 260 |
- |
|
| 261 |
-eval { $dbi->update_param({";" => 1}) };
|
|
| 262 |
-like($@, qr/not safety/); |
|
| 263 |
- |
|
| 264 |
- |
|
| 265 |
-test 'update_param'; |
|
| 266 |
-$dbi = DBIx::Custom->connect; |
|
| 267 |
-eval { $dbi->execute('drop table table1') };
|
|
| 268 |
-$dbi->execute($create_table1_2); |
|
| 269 |
-$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 270 |
-$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 271 |
- |
|
| 272 |
-$param = {key2 => 11};
|
|
| 273 |
-$update_param = $dbi->assign_param($param); |
|
| 274 |
-$sql = <<"EOS"; |
|
| 275 |
-update table1 set $update_param |
|
| 276 |
-where key1 = 1 |
|
| 277 |
-EOS |
|
| 278 |
-$dbi->execute($sql, param => $param, table => 'table1'); |
|
| 279 |
-$result = $dbi->execute('select * from table1;');
|
|
| 280 |
-$rows = $result->all; |
|
| 281 |
-is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
|
| 282 |
- {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 283 |
- "basic"); |
|
| 284 |
- |
|
| 285 |
- |
|
| 286 |
-test 'insert_param'; |
|
| 287 |
-$dbi = DBIx::Custom->connect; |
|
| 288 |
-eval { $dbi->execute('drop table table1') };
|
|
| 289 |
-$dbi->execute($create_table1_2); |
|
| 290 |
-$param = {key1 => 1, key2 => 2};
|
|
| 291 |
-$insert_param = $dbi->insert_param($param); |
|
| 292 |
-$sql = <<"EOS"; |
|
| 293 |
-insert into table1 $insert_param |
|
| 294 |
-EOS |
|
| 295 |
-$dbi->execute($sql, param => $param, table => 'table1'); |
|
| 296 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 297 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 298 |
- |
|
| 299 |
-$dbi = DBIx::Custom->connect; |
|
| 300 |
-$dbi->quote('"');
|
|
| 301 |
-eval { $dbi->execute('drop table table1') };
|
|
| 302 |
-$dbi->execute($create_table1_2); |
|
| 303 |
-$param = {key1 => 1, key2 => 2};
|
|
| 304 |
-$insert_param = $dbi->insert_param($param); |
|
| 305 |
-$sql = <<"EOS"; |
|
| 306 |
-insert into table1 $insert_param |
|
| 307 |
-EOS |
|
| 308 |
-$dbi->execute($sql, param => $param, table => 'table1'); |
|
| 309 |
-is($dbi->select(table => 'table1')->one->{key1}, 1);
|
|
| 310 |
-is($dbi->select(table => 'table1')->one->{key2}, 2);
|
|
| 311 |
- |
|
| 312 |
-eval { $dbi->insert_param({";" => 1}) };
|
|
| 313 |
-like($@, qr/not safety/); |
|
| 314 |
- |
|
| 315 |
- |
|
| 316 | 199 |
test 'join'; |
| 317 | 200 |
$dbi = DBIx::Custom->connect; |
| 318 | 201 |
eval { $dbi->execute('drop table table1') };
|
| ... | ... |
@@ -1636,6 +1519,92 @@ like($@, qr/unexpected "{"/, "error : 2");
|
| 1636 | 1519 |
|
| 1637 | 1520 |
|
| 1638 | 1521 |
### a little complex test |
| 1522 |
+ |
|
| 1523 |
+test 'update_param'; |
|
| 1524 |
+$dbi = DBIx::Custom->connect; |
|
| 1525 |
+eval { $dbi->execute('drop table table1') };
|
|
| 1526 |
+$dbi->execute($create_table1_2); |
|
| 1527 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 1528 |
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 1529 |
+ |
|
| 1530 |
+$param = {key2 => 11};
|
|
| 1531 |
+$update_param = $dbi->update_param($param); |
|
| 1532 |
+$sql = <<"EOS"; |
|
| 1533 |
+update table1 $update_param |
|
| 1534 |
+where key1 = 1 |
|
| 1535 |
+EOS |
|
| 1536 |
+$dbi->execute($sql, param => $param); |
|
| 1537 |
+$result = $dbi->execute('select * from table1;', table => 'table1');
|
|
| 1538 |
+$rows = $result->all; |
|
| 1539 |
+is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
|
| 1540 |
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 1541 |
+ "basic"); |
|
| 1542 |
+ |
|
| 1543 |
+ |
|
| 1544 |
+$dbi = DBIx::Custom->connect; |
|
| 1545 |
+eval { $dbi->execute('drop table table1') };
|
|
| 1546 |
+$dbi->execute($create_table1_2); |
|
| 1547 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 1548 |
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 1549 |
+ |
|
| 1550 |
+$param = {key2 => 11, key3 => 33};
|
|
| 1551 |
+$update_param = $dbi->update_param($param); |
|
| 1552 |
+$sql = <<"EOS"; |
|
| 1553 |
+update table1 $update_param |
|
| 1554 |
+where key1 = 1 |
|
| 1555 |
+EOS |
|
| 1556 |
+$dbi->execute($sql, param => $param); |
|
| 1557 |
+$result = $dbi->execute('select * from table1;', table => 'table1');
|
|
| 1558 |
+$rows = $result->all; |
|
| 1559 |
+is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
|
|
| 1560 |
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 1561 |
+ "basic"); |
|
| 1562 |
+ |
|
| 1563 |
+$dbi = DBIx::Custom->connect; |
|
| 1564 |
+eval { $dbi->execute('drop table table1') };
|
|
| 1565 |
+$dbi->execute($create_table1_2); |
|
| 1566 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 1567 |
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 1568 |
+ |
|
| 1569 |
+$param = {key2 => 11, key3 => 33};
|
|
| 1570 |
+$update_param = $dbi->update_param($param, {no_set => 1});
|
|
| 1571 |
+$sql = <<"EOS"; |
|
| 1572 |
+update table1 set $update_param |
|
| 1573 |
+where key1 = 1 |
|
| 1574 |
+EOS |
|
| 1575 |
+$dbi->execute($sql, param => $param); |
|
| 1576 |
+$result = $dbi->execute('select * from table1;', table => 'table1');
|
|
| 1577 |
+$rows = $result->all; |
|
| 1578 |
+is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 33, key4 => 4, key5 => 5},
|
|
| 1579 |
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 1580 |
+ "update param no_set"); |
|
| 1581 |
+ |
|
| 1582 |
+ |
|
| 1583 |
+eval { $dbi->update_param({";" => 1}) };
|
|
| 1584 |
+like($@, qr/not safety/); |
|
| 1585 |
+ |
|
| 1586 |
+ |
|
| 1587 |
+test 'update_param'; |
|
| 1588 |
+$dbi = DBIx::Custom->connect; |
|
| 1589 |
+eval { $dbi->execute('drop table table1') };
|
|
| 1590 |
+$dbi->execute($create_table1_2); |
|
| 1591 |
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2, key3 => 3, key4 => 4, key5 => 5});
|
|
| 1592 |
+$dbi->insert(table => 'table1', param => {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10});
|
|
| 1593 |
+ |
|
| 1594 |
+$param = {key2 => 11};
|
|
| 1595 |
+$update_param = $dbi->assign_param($param); |
|
| 1596 |
+$sql = <<"EOS"; |
|
| 1597 |
+update table1 set $update_param |
|
| 1598 |
+where key1 = 1 |
|
| 1599 |
+EOS |
|
| 1600 |
+$dbi->execute($sql, param => $param, table => 'table1'); |
|
| 1601 |
+$result = $dbi->execute('select * from table1;');
|
|
| 1602 |
+$rows = $result->all; |
|
| 1603 |
+is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
|
|
| 1604 |
+ {key1 => 6, key2 => 7, key3 => 8, key4 => 9, key5 => 10}],
|
|
| 1605 |
+ "basic"); |
|
| 1606 |
+ |
|
| 1607 |
+ |
|
| 1639 | 1608 |
test 'type option'; # DEPRECATED! |
| 1640 | 1609 |
$dbi = DBIx::Custom->connect( |
| 1641 | 1610 |
data_source => 'dbi:SQLite:dbname=:memory:', |