Created
May 9, 2019 22:33
-
-
Save hoehrmann/e3ed3f810c635003e0be2bf3a77a85a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use DBI; | |
use JSON; | |
use YAML::XS; | |
my $dbh = DBI->connect('dbi:SQLite:dbname=:memory:'); | |
our $Arg; | |
$dbh->sqlite_create_function('param', 0, sub { | |
return $Arg; | |
}); | |
$dbh->sqlite_create_function('eval', 2, sub { | |
my ($sql, $arg) = @_; | |
local $Arg = $arg; | |
my $result = $dbh->selectall_arrayref($sql, { Slice => {} }); | |
return JSON->new->encode($result); | |
}); | |
$dbh->do(q{ | |
CREATE VIEW view_with_param AS | |
SELECT 'first row' AS name, param() AS param | |
UNION ALL | |
SELECT 'second row' AS name, param() AS param | |
}); | |
print Dump ( | |
$dbh->selectall_arrayref(q{ | |
SELECT * FROM (SELECT eval( | |
'SELECT * FROM view_with_param', | |
'[1,2,3]' | |
)) | |
}) | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment