core icon indicating copy to clipboard operation
core copied to clipboard

Multi_query feature

Open SCIF opened this issue 13 years ago • 7 comments

Suggest to add something like php built-in mysqli->multi_query function. Current implementation of DB class can't to handle sql with definition mysql triggers/stored routne with delimiter change because method query() execute only one query to first ocassion of ;

SCIF avatar Jun 08 '12 13:06 SCIF

@SCIF it's a bit overdue, but what's the usecase you want to handle? Import an sql file?

frankdejonge avatar Apr 26 '13 11:04 frankdejonge

I wanted to import triggers via migrations.

SCIF avatar Apr 28 '13 23:04 SCIF

@FrenkyNet does Cabinet support multiple queries and PDO::nextRowset() ?

If so, this can be closed as addressed in 2.0.

WanWizard avatar Aug 29 '13 13:08 WanWizard

@WanWizard I'm still looking for a good resource, haven't found one thus far

frankdejonge avatar Aug 29 '13 13:08 frankdejonge

Resource, in the sense of an example of how it works?

That is pretty simple. There where you now do a fetchAll(), you loop over the resultsets and do a fetchAll() for each one. See example 1: http://php.net/manual/en/pdostatement.nextrowset.php

Big question here whether you build this into execute(), or if you use a fetchNextResult() method which you can call manually if there are more results.

This functionality is required when using stored procedures, so it's handy to have.

WanWizard avatar Aug 30 '13 12:08 WanWizard

Hehe, I know how the next rowset function works, the biggest issue is; what should the api be like? I haven't thought of a nice way to do so. I'll keep my eyes out for it. Any suggestions are welcome! I'd be happy to code it up.

frankdejonge avatar Aug 30 '13 18:08 frankdejonge

It's now implemented as a "one-stop-shop": executeSelect() receives the query, executes it, and returns the result.

So you either implement it in there (which would make the return value variable, since you'll have to return an array of results in case you have multiple), or split that into an execute() and a fetch() method, so you can do mutliple fetch() calls on a single query result.

WanWizard avatar Aug 30 '13 19:08 WanWizard