Generating SQL with Zend\Db\Sql\Insert

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Generating SQL with Zend\Db\Sql\Insert

umpirsky
Hi.

I'm trying to generate some SQL for all DBMS-es. Since there is no way to
generate CREATE TABLE with Zend\Db (correct me if I'm wrong), I use
Doctrine for that
http://groups.google.com/group/doctrine-user/browse_frm/thread/4b14e98a0d9ded98.
And since there is no way to generate insert with Doctrine, I tried with
\Zend\Db\Sql\Insert, and it works:

$insert = new \Zend\Db\Sql\Insert('mytable');
foreach ($data as $id => $name) {
    $insert->values(array('id' => $id, 'name' => $name),
Insert::VALUES_MERGE);
}

$insert->getSqlString(new \Zend\Db\Adapter\Platform\Mysql());

The problem is I find only few platforms there, no PostgreSQL for example,
which was available in Zend Framework 1. Am I missing something?

All tips are ewlcome, thanks.
---
Regards,
Saša Stamenković
Reply | Threaded
Open this post in threaded view
|

Re: Generating SQL with Zend\Db\Sql\Insert

robertbasic
On Mon, Mar 5, 2012 at 12:40 PM, Саша Стаменковић <[hidden email]> wrote:
> Hi.
>
> I'm trying to generate some SQL for all DBMS-es. Since there is no way to
> generate CREATE TABLE with Zend\Db (correct me if I'm wrong),

See this for doing CREATE TABLE queries:
https://github.com/robertbasic/zf2/blob/3a00fd3b323e3ef74d4e3bbab4cdcb5f3d73fdeb/tests/Zend/Feed/PubSubHubbub/Model/SubscriptionTest.php#L74
maybe not the best solution, but should get you in the right
direction.

> The problem is I find only few platforms there, no PostgreSQL for example,
> which was available in Zend Framework 1. Am I missing something?

Not all platforms are refactored yet, AFAIK. See
http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Refactored-in-Beta3-td4415308.html
for more details on the refactoring.

--
~Robert Basic;
http://robertbasic.com/

--
List: [hidden email]
Info: http://framework.zend.com/archives
Unsubscribe: [hidden email]


Reply | Threaded
Open this post in threaded view
|

Re: Generating SQL with Zend\Db\Sql\Insert

umpirsky
Hi.

Let me explain again, I would like to just generate CREATE TABLE and INSERT
statements for all DBMS-es. So, I just want to export my data to SQL, I
don't have a database. The result of my script will be a few SQL scripts,
one for each DBMS.

So, your CREATE TABLE example will not help me to generate CREATE TABLE
statement for each DBMS.

Thanks for your fast response.
---
Regards,
Saša Stamenković


On Mon, Mar 5, 2012 at 12:43 PM, Robert Basic <[hidden email]>wrote:

> On Mon, Mar 5, 2012 at 12:40 PM, Саша Стаменковић <[hidden email]>
> wrote:
> > Hi.
> >
> > I'm trying to generate some SQL for all DBMS-es. Since there is no way to
> > generate CREATE TABLE with Zend\Db (correct me if I'm wrong),
>
> See this for doing CREATE TABLE queries:
>
> https://github.com/robertbasic/zf2/blob/3a00fd3b323e3ef74d4e3bbab4cdcb5f3d73fdeb/tests/Zend/Feed/PubSubHubbub/Model/SubscriptionTest.php#L74
> maybe not the best solution, but should get you in the right
> direction.
>
> > The problem is I find only few platforms there, no PostgreSQL for
> example,
> > which was available in Zend Framework 1. Am I missing something?
>
> Not all platforms are refactored yet, AFAIK. See
>
> http://zend-framework-community.634137.n4.nabble.com/Zend-Db-Refactored-in-Beta3-td4415308.html
> for more details on the refactoring.
>
> --
> ~Robert Basic;
> http://robertbasic.com/
>
Reply | Threaded
Open this post in threaded view
|

Re: Generating SQL with Zend\Db\Sql\Insert

umpirsky
Can Zend\Db\Sql\Insert make a bulk insert?