Re: [fw-general] Specifying a Database Adapter and Zend_Application_Resource_Multidb

2010-10-02 Thread Hector Virgen
The simplest way to do this is to not extend Zend_Db_Table_Abstract. In ZF,
tables are not models. I've gone down this route personally and it's very
difficult to do anything slightly complex loo ike dealing with multiple
tables.

Instead, I suggest creating a model that doesn't extend a base class, and
have that model instantiate the table(s) it needs. The model can then inject
the correct db instance if necessary.

--
Hector Virgen
Sent from my Droid X
On Oct 2, 2010 10:12 AM, "EvilThug"  wrote:


Re: [fw-general] Select object behaviour

2010-10-02 Thread Valeriy Yatsko
Good day

> Yes, but it doesnt seem right to assume someones app will have the same
> amount or rows that is equesl to the max integer the os can hold?

You really have table larger than 2 000 000 000 entries on 32-bit servers? :)

Let's see... int = 4 bytes on 32 bit systems:
2 000 000 000 x 4 = 8 000 000 000 = ~ 8 gb minimum per table :)

Let's add here at least varchar(255):
2 000 000 000 x (4 + 255) = 518 000 000 000 = ~ 518 gb per table :)

Try to search some data through this table. :)

There are some architecture solutions for this, like splitting tables into 
smaller (or shards).

--
Валерий Яцко
__
d...@design.ru | http://www.artlebedev.ru

Re: [fw-general] Select object behaviour

2010-10-02 Thread Daniel Latter
Yes, but it doesnt seem right to assume someones app will have the same
amount or rows that is equesl to the max integer the os can hold?

Daniel

2010/10/3 Valeriy Yatsko 

> Good day
>
> > So limit 0 (or limit null, or limit false) would remove the limit portion
> if
> > the query?
>
> True.
>
> As long as you have entries amount less than PHP_INT_MAX (which is
> different for 32-bit and 64-bit systems).
>
> Mac OS X Snow Leopard 10.6.4 (64 bit)
>
> dwr:~ dwr$ php intmax.php
> 9223372036854775807
> dwr:~ dwr$
>
> Debian Lenny 5.0 (32 bit)
>
> dwr:~ dev1$ php intmax.php
> 2147483647
> dwr:~ dev1$
>
> --
> Валерий Яцко
> __
> d...@design.ru | http://www.artlebedev.ru
>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Valeriy Yatsko
Good day

> So limit 0 (or limit null, or limit false) would remove the limit portion if
> the query?

True.

As long as you have entries amount less than PHP_INT_MAX (which is different 
for 32-bit and 64-bit systems).

Mac OS X Snow Leopard 10.6.4 (64 bit)

dwr:~ dwr$ php intmax.php 
9223372036854775807
dwr:~ dwr$ 

Debian Lenny 5.0 (32 bit)

dwr:~ dev1$ php intmax.php 
2147483647
dwr:~ dev1$ 

--
Валерий Яцко
__
d...@design.ru | http://www.artlebedev.ru

Re: [fw-general] Select object behaviour

2010-10-02 Thread Hector Virgen
Regardless of how it actually works, I would expect limit null or limit
false to remove the limit portion if the query, while limit 0 would do an
actual limit 0. Having it do a limit 2.1 bajillion is just strange and
unexpected behavior.

Just my 2c.

--
Hector Virgen
Sent from my Droid X
On Oct 2, 2010 5:28 PM, "Daniel Latter"  wrote:
> OK, so it doesnt seem to be a bug judging by what Valeriy said and the
link
> posted but i think this maybe a bit drastic, as Hector said I think limit
0,
> null or false should just remove or even dont add the limit part?
>
> Daniel.
>
> On 3 October 2010 01:24, Hector Virgen  wrote:
>
>> So limit 0 (or limit null, or limit false) would remove the limit portion
>> if the query?
>>
>> --
>> Hector Virgen
>> Sent from my Droid X
>> On Oct 2, 2010 5:21 PM, "Daniel Latter"  wrote:
>> > or just throw away the limit part altogether?
>> >
>> > Daniel
>> >
>> > On 3 October 2010 01:17, Hector Virgen  wrote:
>> >
>> >> Limit 0 us definitely an incorrect usage, so maybe an exception should
>> be
>> >> thrown?
>> >>
>> >> --
>> >> Hector Virgen
>> >> Sent from my Droid X
>> >> On Oct 2, 2010 5:15 PM, "Daniel Latter"  wrote:
>> >> > Hi,
>> >> >
>> >> > I know what your saying but my point is that, is this intended
>> behaviour
>> >> to
>> >> > return a number so large if a zero happend to be passed.?
>> >> >
>> >> > Thanks
>> >> > Daniel.
>> >> >
>> >> > 2010/10/3 Valeriy Yatsko 
>> >> >
>> >> >> Good day
>> >> >>
>> >> >> > dont know if this is a bug or not but if you pass the following
>> >> >> parameters
>> >> >> > to the limit method on select object like so:
>> >> >> >
>> >> >> > ->limit(0, 10);
>> >> >> >
>> >> >> > It produces the following SQL:
>> >> >> >
>> >> >> > LIMIT 2147483647 OFFSET 10
>> >> >> >
>> >> >> > now i know you should vaidate the limit val beforehand but this
>> could
>> >> >> > potentially kill someones app?
>> >> >>
>> >> >>
>> >> >> In Zend_Db_Select, you can use the limit() method to specify the
>> count
>> >> of
>> >> >> rows and the number of rows to skip. The first argument to this
>> method
>> >> is
>> >> >> the desired count of rows. The second argument is the number of
rows
>> to
>> >> >> skip.
>> >> >>
>> >> >> So you should use
>> >> >> ->limit(10,0)
>> >> >> instead.
>> >> >>
>> >> >> --
>> >> >> Валерий Яцко
>> >> >>
>> __
>> >> >> d...@design.ru | http://www.artlebedev.ru
>> >> >>
>> >> >>
>> >>
>>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Daniel Latter
OK, so it doesnt seem to be a bug judging by what Valeriy said and the link
posted but i think this maybe a bit drastic, as Hector said I think limit 0,
null or false should just remove or even dont add the limit part?

Daniel.

On 3 October 2010 01:24, Hector Virgen  wrote:

> So limit 0 (or limit null, or limit false) would remove the limit portion
> if the query?
>
> --
> Hector Virgen
> Sent from my Droid X
> On Oct 2, 2010 5:21 PM, "Daniel Latter"  wrote:
> > or just throw away the limit part altogether?
> >
> > Daniel
> >
> > On 3 October 2010 01:17, Hector Virgen  wrote:
> >
> >> Limit 0 us definitely an incorrect usage, so maybe an exception should
> be
> >> thrown?
> >>
> >> --
> >> Hector Virgen
> >> Sent from my Droid X
> >> On Oct 2, 2010 5:15 PM, "Daniel Latter"  wrote:
> >> > Hi,
> >> >
> >> > I know what your saying but my point is that, is this intended
> behaviour
> >> to
> >> > return a number so large if a zero happend to be passed.?
> >> >
> >> > Thanks
> >> > Daniel.
> >> >
> >> > 2010/10/3 Valeriy Yatsko 
> >> >
> >> >> Good day
> >> >>
> >> >> > dont know if this is a bug or not but if you pass the following
> >> >> parameters
> >> >> > to the limit method on select object like so:
> >> >> >
> >> >> > ->limit(0, 10);
> >> >> >
> >> >> > It produces the following SQL:
> >> >> >
> >> >> > LIMIT 2147483647 OFFSET 10
> >> >> >
> >> >> > now i know you should vaidate the limit val beforehand but this
> could
> >> >> > potentially kill someones app?
> >> >>
> >> >>
> >> >> In Zend_Db_Select, you can use the limit() method to specify the
> count
> >> of
> >> >> rows and the number of rows to skip. The first argument to this
> method
> >> is
> >> >> the desired count of rows. The second argument is the number of rows
> to
> >> >> skip.
> >> >>
> >> >> So you should use
> >> >> ->limit(10,0)
> >> >> instead.
> >> >>
> >> >> --
> >> >> Валерий Яцко
> >> >>
> __
> >> >> d...@design.ru | http://www.artlebedev.ru
> >> >>
> >> >>
> >>
>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Hector Virgen
So limit 0 (or limit null, or limit false) would remove the limit portion if
the query?

--
Hector Virgen
Sent from my Droid X
On Oct 2, 2010 5:21 PM, "Daniel Latter"  wrote:
> or just throw away the limit part altogether?
>
> Daniel
>
> On 3 October 2010 01:17, Hector Virgen  wrote:
>
>> Limit 0 us definitely an incorrect usage, so maybe an exception should be
>> thrown?
>>
>> --
>> Hector Virgen
>> Sent from my Droid X
>> On Oct 2, 2010 5:15 PM, "Daniel Latter"  wrote:
>> > Hi,
>> >
>> > I know what your saying but my point is that, is this intended
behaviour
>> to
>> > return a number so large if a zero happend to be passed.?
>> >
>> > Thanks
>> > Daniel.
>> >
>> > 2010/10/3 Valeriy Yatsko 
>> >
>> >> Good day
>> >>
>> >> > dont know if this is a bug or not but if you pass the following
>> >> parameters
>> >> > to the limit method on select object like so:
>> >> >
>> >> > ->limit(0, 10);
>> >> >
>> >> > It produces the following SQL:
>> >> >
>> >> > LIMIT 2147483647 OFFSET 10
>> >> >
>> >> > now i know you should vaidate the limit val beforehand but this
could
>> >> > potentially kill someones app?
>> >>
>> >>
>> >> In Zend_Db_Select, you can use the limit() method to specify the count
>> of
>> >> rows and the number of rows to skip. The first argument to this method
>> is
>> >> the desired count of rows. The second argument is the number of rows
to
>> >> skip.
>> >>
>> >> So you should use
>> >> ->limit(10,0)
>> >> instead.
>> >>
>> >> --
>> >> Валерий Яцко
>> >> __
>> >> d...@design.ru | http://www.artlebedev.ru
>> >>
>> >>
>>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Valeriy Yatsko
Good day

> The example I am thinking of is an app could very well have millions of
> rows, and if you did happen to pass a zero you would most probably end up
> killing the server with an out of memory error, or timeout issues... and
> thus bring you app crashing down.


Judging with protected function _renderLimitoffset($sql) in 
http://framework.zend.com/svn/framework/standard/trunk/library/Zend/Db/Select.php,
 that large limit is PHP_INT_MAX and is related to select all entries from the 
offset to the end of database, no?

--
Валерий Яцко
__
d...@design.ru | http://www.artlebedev.ru


Re: [fw-general] Select object behaviour

2010-10-02 Thread Daniel Latter
or just throw away the limit part altogether?

Daniel

On 3 October 2010 01:17, Hector Virgen  wrote:

> Limit 0 us definitely an incorrect usage, so maybe an exception should be
> thrown?
>
> --
> Hector Virgen
> Sent from my Droid X
> On Oct 2, 2010 5:15 PM, "Daniel Latter"  wrote:
> > Hi,
> >
> > I know what your saying but my point is that, is this intended behaviour
> to
> > return a number so large if a zero happend to be passed.?
> >
> > Thanks
> > Daniel.
> >
> > 2010/10/3 Valeriy Yatsko 
> >
> >> Good day
> >>
> >> > dont know if this is a bug or not but if you pass the following
> >> parameters
> >> > to the limit method on select object like so:
> >> >
> >> > ->limit(0, 10);
> >> >
> >> > It produces the following SQL:
> >> >
> >> > LIMIT 2147483647 OFFSET 10
> >> >
> >> > now i know you should vaidate the limit val beforehand but this could
> >> > potentially kill someones app?
> >>
> >>
> >> In Zend_Db_Select, you can use the limit() method to specify the count
> of
> >> rows and the number of rows to skip. The first argument to this method
> is
> >> the desired count of rows. The second argument is the number of rows to
> >> skip.
> >>
> >> So you should use
> >> ->limit(10,0)
> >> instead.
> >>
> >> --
> >> Валерий Яцко
> >> __
> >> d...@design.ru | http://www.artlebedev.ru
> >>
> >>
>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Daniel Latter
The example I am thinking of is an app could very well have millions of
rows, and if you did happen to pass a zero you would most probably end up
killing the server with an out of memory error, or timeout issues... and
thus bring you app crashing down.

Daniel.

2010/10/3 Daniel Latter 

> Hi,
>
> I know what your saying but my point is that, is this intended behaviour to
> return a number so large if a zero happend to be passed.?
>
> Thanks
> Daniel.
>
> 2010/10/3 Valeriy Yatsko 
>
> Good day
>>
>> > dont know if this is a bug or not but if you pass the following
>> parameters
>> > to the limit method on select object like so:
>> >
>> > ->limit(0, 10);
>> >
>> > It produces the following SQL:
>> >
>> > LIMIT 2147483647 OFFSET 10
>> >
>> > now i know you should vaidate the limit val beforehand but this could
>> > potentially kill someones app?
>>
>>
>> In Zend_Db_Select, you can use the limit() method to specify the count of
>> rows and the number of rows to skip. The first argument to this method is
>> the desired count of rows. The second argument is the number of rows to
>> skip.
>>
>> So you should use
>> ->limit(10,0)
>> instead.
>>
>> --
>> Валерий Яцко
>> __
>> d...@design.ru | http://www.artlebedev.ru
>>
>>
>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Hector Virgen
Limit 0 us definitely an incorrect usage, so maybe an exception should be
thrown?

--
Hector Virgen
Sent from my Droid X
On Oct 2, 2010 5:15 PM, "Daniel Latter"  wrote:
> Hi,
>
> I know what your saying but my point is that, is this intended behaviour
to
> return a number so large if a zero happend to be passed.?
>
> Thanks
> Daniel.
>
> 2010/10/3 Valeriy Yatsko 
>
>> Good day
>>
>> > dont know if this is a bug or not but if you pass the following
>> parameters
>> > to the limit method on select object like so:
>> >
>> > ->limit(0, 10);
>> >
>> > It produces the following SQL:
>> >
>> > LIMIT 2147483647 OFFSET 10
>> >
>> > now i know you should vaidate the limit val beforehand but this could
>> > potentially kill someones app?
>>
>>
>> In Zend_Db_Select, you can use the limit() method to specify the count of
>> rows and the number of rows to skip. The first argument to this method is
>> the desired count of rows. The second argument is the number of rows to
>> skip.
>>
>> So you should use
>> ->limit(10,0)
>> instead.
>>
>> --
>> Валерий Яцко
>> __
>> d...@design.ru | http://www.artlebedev.ru
>>
>>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Daniel Latter
Hi,

I know what your saying but my point is that, is this intended behaviour to
return a number so large if a zero happend to be passed.?

Thanks
Daniel.

2010/10/3 Valeriy Yatsko 

> Good day
>
> > dont know if this is a bug or not but if you pass the following
> parameters
> > to the limit method on select object like so:
> >
> > ->limit(0, 10);
> >
> > It produces the following SQL:
> >
> > LIMIT 2147483647 OFFSET 10
> >
> > now i know you should vaidate the limit val beforehand but this could
> > potentially kill someones app?
>
>
> In Zend_Db_Select, you can use the limit() method to specify the count of
> rows and the number of rows to skip. The first argument to this method is
> the desired count of rows. The second argument is the number of rows to
> skip.
>
> So you should use
> ->limit(10,0)
> instead.
>
> --
> Валерий Яцко
> __
> d...@design.ru | http://www.artlebedev.ru
>
>


Re: [fw-general] Select object behaviour

2010-10-02 Thread Valeriy Yatsko
Good day

> dont know if this is a bug or not but if you pass the following parameters
> to the limit method on select object like so:
> 
> ->limit(0, 10);
> 
> It produces the following SQL:
> 
> LIMIT 2147483647 OFFSET 10
> 
> now i know you should vaidate the limit val beforehand but this could
> potentially kill someones app?


In Zend_Db_Select, you can use the limit() method to specify the count of rows 
and the number of rows to skip. The first argument to this method is the 
desired count of rows. The second argument is the number of rows to skip.

So you should use
->limit(10,0)
instead.

--
Валерий Яцко
__
d...@design.ru | http://www.artlebedev.ru



[fw-general] Select object behaviour

2010-10-02 Thread Daniel Latter
Hi All,

dont know if this is a bug or not but if you pass the following parameters
to the limit method on select object like so:

->limit(0, 10);

It produces the following SQL:

LIMIT 2147483647 OFFSET 10

now i know you should vaidate the limit val beforehand but this could
potentially kill someones app?

Thanks
Daniel.


[fw-general] Specifying a Database Adapter and Zend_Application_Resource_Multidb

2010-10-02 Thread EvilThug
How do I code the correct database adapter into a model class that extends
the Zend_Db_Table_Abstract?

 

I am using Zend_Application_Resource_Multidb in my config in
application/configs/application.ini:

 

-

resources.multidb.db1.adapter = "pdo_mysql"

resources.multidb.db1.host = "myhost1"

resources.multidb.db1.username = "myuser6854"

resources.multidb.db1.password = "mypassword"

resources.multidb.db1.dbname = "mydb0001"

resources.multidb.db1.isDefaultTableAdapter = true

 

resources.multidb.db2.adapter = "pdo_mysql"

resources.multidb.db2.host = "myhost2"

resources.multidb.db2.username = "myuser5242"

resources.multidb.db2.password = "mypassword"

resources.multidb.db2.dbname = "mydb0002"

-

 

Inside my in application/bootstrap.php, I think I am loading the database
adapters. At least the default works without a problem:

 

-

protected function _initDB()

{

  $resource = $this->getPluginResource('multidb');

  $resource->init();

  $db1 = $resource->getDb('db1');

  $db2 = $resource->getDb('db2');

  $defaultDb = $resource->getDb();

}

-

 

Inside my model classes, I understand that the property is within the
Zend_Db_Table_Abstract:

 

-

/**

 * Zend_Db_Adapter_Abstract object.

 *

 * @var Zend_Db_Adapter_Abstract

*/

protected $_db;

-

 

How do I set the $_db property to correct database adapter from inside the
model?

 

Inside a controller, I can do the following:

 

-

...

$bootstrap = $this->getInvokeArg('bootstrap');

$resource = $bootstrap->getPluginResource('multidb');

$db2 = $resource->getDb('db2');

$model = new Model_MyTable($db2);

...

-

 

However, I don't just instance Models from inside Controllers. Also, I would
like to set the correct database adapter inside the model itself, so that
anything outside the Model doesn't need to understand the workings of my
databases.

 

There is another problem, If I want to create join that works with two
databases (and thus two database adapters), under the current architecture,
how can I do that?

 

Let me say up front, I want the Zend Framework to work for me, not the other
way around. The framework needs to provide a clear and uncomplicated way of
doing something that saves me time from writing it from scratch. That said,
I am new to Zend Framework and working through my first major deliverable
with it. Since this is my first time using the Framework I expect some
misunderstanding and hiccups.

 

Thanks for any help or insight.