Showing 1 changed files with 40 additions and 37 deletions
+40 -37
t/basic.t
... ...
@@ -46,6 +46,7 @@ my $model2;
46 46
 my $where;
47 47
 my $update_param;
48 48
 my $insert_param;
49
+my $join;
49 50
 
50 51
 # Prepare table
51 52
 $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
... ...
@@ -2048,30 +2049,32 @@ is_deeply($rows, [{key1 => 1, key2 => 11, key3 => 3, key4 => 4, key5 => 5},
2048 2049
 
2049 2050
 
2050 2051
 test 'insert_param';
2051
-{
2052
-    $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2053
-    $dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
2054
-    $param = {key1 => 1, key2 => 2};
2055
-    my $insert_param = $dbi->insert_param($param);
2056
-    $sql = "insert into table1 $insert_param";
2057
-    $dbi->execute($sql, param => $param, table => 'table1');
2058
-    is($dbi->select(table => 'table1')->one->{key1}, 1);
2059
-    is($dbi->select(table => 'table1')->one->{key2}, 2);
2060
-}
2061
-{
2062
-    $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2063
-    $dbi->quote('"');
2064
-    $dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
2065
-    $param = {key1 => 1, key2 => 2};
2066
-    my $insert_param = $dbi->insert_param($param);
2067
-    $sql = "insert into table1 $insert_param";
2068
-    $dbi->execute($sql, param => $param, table => 'table1');
2069
-    is($dbi->select(table => 'table1')->one->{key1}, 1);
2070
-    is($dbi->select(table => 'table1')->one->{key2}, 2);
2071
-
2072
-    eval { $dbi->insert_param({";" => 1}) };
2073
-    like($@, qr/not safety/);
2074
-}
2052
+$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2053
+$dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
2054
+$param = {key1 => 1, key2 => 2};
2055
+$insert_param = $dbi->insert_param($param);
2056
+$sql = <<"EOS";
2057
+insert into table1 $insert_param
2058
+EOS
2059
+$dbi->execute($sql, param => $param, table => 'table1');
2060
+is($dbi->select(table => 'table1')->one->{key1}, 1);
2061
+is($dbi->select(table => 'table1')->one->{key2}, 2);
2062
+
2063
+$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2064
+$dbi->quote('"');
2065
+$dbi->execute('create table table1 (key1 char(255), key2 char(255), key3 char(255), key4 char(255), key5 char(255));');
2066
+$param = {key1 => 1, key2 => 2};
2067
+$insert_param = $dbi->insert_param($param);
2068
+$sql = <<"EOS";
2069
+insert into table1 $insert_param
2070
+EOS
2071
+$dbi->execute($sql, param => $param, table => 'table1');
2072
+is($dbi->select(table => 'table1')->one->{key1}, 1);
2073
+is($dbi->select(table => 'table1')->one->{key2}, 2);
2074
+
2075
+eval { $dbi->insert_param({";" => 1}) };
2076
+like($@, qr/not safety/);
2077
+
2075 2078
 
2076 2079
 test 'join';
2077 2080
 $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
... ...
@@ -2161,11 +2164,11 @@ is_deeply($rows, [{table1_key1 => 1, table2_key1 => 1, key2 => 2, key3 => 5}],
2161 2164
         return $self;
2162 2165
     }
2163 2166
 }
2164
-{
2165
-    $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2166
-    $dbi->execute('create table table1 (key1 char(255), key2 char(255));');
2167
-    $dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2168
-    $sql = <<"EOS";
2167
+
2168
+$dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2169
+$dbi->execute('create table table1 (key1 char(255), key2 char(255));');
2170
+$dbi->insert(table => 'table1', param => {key1 => 1, key2 => 2});
2171
+$sql = <<"EOS";
2169 2172
 left outer join (
2170 2173
   select * from table1 as t1
2171 2174
   where t1.key2 = (
... ...
@@ -2174,14 +2177,14 @@ left outer join (
2174 2177
   )
2175 2178
 ) as latest_table1 on table1.key1 = latest_table1.key1
2176 2179
 EOS
2177
-    my $join = [$sql];
2178
-    $rows = $dbi->select(
2179
-        table => 'table1',
2180
-        column => 'latest_table1.key1 as latest_table1__key1',
2181
-        join  => $join
2182
-    )->all;
2183
-    is_deeply($rows, [{latest_table1__key1 => 1}]);
2184
-}
2180
+$join = [$sql];
2181
+$rows = $dbi->select(
2182
+    table => 'table1',
2183
+    column => 'latest_table1.key1 as latest_table1__key1',
2184
+    join  => $join
2185
+)->all;
2186
+is_deeply($rows, [{latest_table1__key1 => 1}]);
2187
+
2185 2188
 $dbi = DBIx::Custom->connect(dsn => 'dbi:SQLite:dbname=:memory:');
2186 2189
 $dbi->execute('create table table1 (key1 char(255), key2 char(255));');
2187 2190
 $dbi->execute('create table table2 (key1 char(255), key3 char(255));');