afterdead / db2php

Automatically exported from code.google.com/p/db2php
GNU General Public License v3.0
0 stars 0 forks source link

Documentação - Como fazer #5

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
Gostaria de saber como faço para fazer select personalizada exemplo: 
select count(o) from MinhaClass o where o.nome like '%x%' 

Original issue reported on code.google.com by marcoamv...@gmail.com on 16 Jul 2009 at 12:22

GoogleCodeExporter commented 8 years ago
Sorry, I don't know any spanish ^^
I guess you want OQL?
Sorry, I surely won't write an OQL parser in _PHP_ ;)
But the feature for the next release will be filter object support, so you can 
write:
MinhaClass::getByFilter($db, array(new 
DataFilterElement(MinhaClass::FIELD_NOME, 
DataFilterElement::CONTAINS, 'x')));

Cheers ^^

Original comment by rc.poi...@gmail.com on 16 Jul 2009 at 7:45

GoogleCodeExporter commented 8 years ago
I speak Portuguese in Brazil is not Spanish ... ^^

I wonder how to select a personal example:
select count (o) from the MinhaClass where o.nome like '% x%'

Note: I would like to thank the great initiative ...

Original comment by marcoamv...@gmail.com on 16 Jul 2009 at 7:51

GoogleCodeExporter commented 8 years ago
>I speak Portuguese in Brazil is not Spanish
Sorry, my bad :)

Sorry, but the OQL example you provided will never be implemented by myself.

At the moment the whole thing is much too simple to be good ^^
Query by example/filter will only match exact values.
Right now you'd have to write your own code do realise the example you posted.

I'm working on filter objects though, which would be a bit more flexible for 
matching (hopefully finished next week or so).

But counting like in your example would still be a better idea in to do in SQL 
directly, as my projects goal is to provide Entitiy classes which allow easy 
fetching / updating and inserting for OOP code, and thus would involve fetching 
all 
matched rows as objects and then counting them. Since that would be rather 
inefficient (especially in PHP), well, ... not a good idea :)

I'm sorry, my english isn't very good, I hope I've answered the right question 
^^

And your welcome :)

Original comment by rc.poi...@gmail.com on 16 Jul 2009 at 8:18

GoogleCodeExporter commented 8 years ago
[deleted comment]
GoogleCodeExporter commented 8 years ago

But you have implemented some method where I can pass this sql and thus get the
result you desire. I understand the situation of your project but I would like 
to
know if I can do this using the select model because you implemented using java 
you
can use a generic method that is more specific searches. Because not yet 
learned to
use all the features you implemented and would like to know if you could help 
me. I
guarantee that many people go through this difficulty IRAM too.

Note: It would be an interesting documentation with examples of all methods 
that you
created this very helpful.

Do not understand your suggestion could make an example.

Original comment by marcoamv...@gmail.com on 17 Jul 2009 at 11:52

GoogleCodeExporter commented 8 years ago
Version 1.2.4 is out which allows filters.
Download the NetBeans pluin, upgrade, regerenate your Class (you have to
delete/rename it first).
You'll also need the source package which contains the DCF.class.php.

To implement your example:
$db=new PDO('mysql:dbname=yourdb;host=localhost', 'user', 'passwd');
include_once 'DFC.class.php';
echo count(
  MinhaClass::getByFilter(
    $db,
    array(
      new DFC(MinhaClass::FIELD_NOME, 'x', DFC::CONTAINS) // new filter on field
nome, where the value contains x
    )
  )
);

Examples and explainations will be coming next week (updated the HOWTO a time 
bit)...
sry, yesterday was my birthday and I intend to pary till sunday :P
have fun ^^

Original comment by rc.poi...@gmail.com on 17 Jul 2009 at 1:18

GoogleCodeExporter commented 8 years ago

Original comment by rc.poi...@gmail.com on 17 Jul 2009 at 1:19

GoogleCodeExporter commented 8 years ago
Congratulations on your anniversary and thanks for the help I download and test 
the
new version ... have a good rest ...

Original comment by marcoamv...@gmail.com on 17 Jul 2009 at 1:48

GoogleCodeExporter commented 8 years ago
Ok, I've released 1.2.5.
It contains a bit of what you could consider 'examples' in the test folder (in 
the
source package).
I've also started a wiki page for the relevant generated methods:
http://code.google.com/p/db2php/wiki/GeneratedMethods .

Could you do be a favor and tell me which parts aren't clear from the PHPDoc 
and the
examples. Or any questions you have left.
I always find it a bit hard to write good doc for my own code ^^

Thanks

Original comment by rc.poi...@gmail.com on 20 Jul 2009 at 5:59