Saving INSERTs without inserting

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Saving INSERTs without inserting

Bill Moseley
I have a test script that generates a large number of inserts.   What I'd like to do is capture the SQL inserts into a file so I can later run the inserts using psql -f foo.sql or psql's \i command.

I thought I might get lucky and call ->new_result( \%cols )->as_query, but no.

I know I can create a debug object and capture on ->query_start calls.    But, I'd like to not actually insert into the database.

I suppose I could die in the query_start method and eval every insert.

Any other ideas how to capture the insert SQL without actually inserting?


--
Bill Moseley
[hidden email]

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Saving INSERTs without inserting

Francesco Serra
As per doc, ->new_result creates a new $result, and therefore you're calling ->as_query on an object which doesn't have that method, which, instead, is described in the ResultSet class.

On Wed, 21 Oct 2015 at 16:00 Bill Moseley <[hidden email]> wrote:
I have a test script that generates a large number of inserts.   What I'd like to do is capture the SQL inserts into a file so I can later run the inserts using psql -f foo.sql or psql's \i command.

I thought I might get lucky and call ->new_result( \%cols )->as_query, but no.

I know I can create a debug object and capture on ->query_start calls.    But, I'd like to not actually insert into the database.

I suppose I could die in the query_start method and eval every insert.

Any other ideas how to capture the insert SQL without actually inserting?


--
Bill Moseley
[hidden email]
_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...
Reply | Threaded
Open this post in threaded view
|

Re: Saving INSERTs without inserting

Trevor Leffler
In reply to this post by Bill Moseley
How about wrapping the whole thing in a transaction ending with a
rollback, turn on DBIC_TRACE and redirect the output to your file.
Would something like that work?

Cheers,
--Trevor

On 10/21/2015 07:59 AM, Bill Moseley wrote:

> I have a test script that generates a large number of inserts.   What
> I'd like to do is capture the SQL inserts into a file so I can later run
> the inserts using psql -f foo.sql or psql's \i command.
>
> I thought I might get lucky and call ->new_result( \%cols )->as_query,
> but no.
>
> I know I can create a debug object and capture on ->query_start calls.
>   But, I'd like to /not/ actually insert into the database.
>
> I suppose I could die in the query_start method and eval every insert.
>
> Any other ideas how to capture the insert SQL without actually inserting?
>
>
> --
> Bill Moseley
> [hidden email] <mailto:[hidden email]>
>
>
> _______________________________________________
> List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
> IRC: irc.perl.org#dbix-class
> SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
> Searchable Archive: http://www.grokbase.com/group/dbix-class@...
>

_______________________________________________
List: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/dbix-class
IRC: irc.perl.org#dbix-class
SVN: http://dev.catalyst.perl.org/repos/bast/DBIx-Class/
Searchable Archive: http://www.grokbase.com/group/dbix-class@...