 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
|
 |
|
 |
07-30-2009, 02:01 PM
|
#81 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Quote:
|
ETbyrne, what made you give it the name dingo ?.. if i may ask..
|
Idk, it just kinda came to mind.
Quote:
|
ET, I also checked out his ACL system and while simple-looking is very robust, it's the mark of good programming to make something which is useful and preforms a complicated task ( Full fledged ACL Systems are indeed complex ) and yet still remain simply written. I don't really even need to see the commenting to understand the flow, the same cannot be said about many other scripts.
|
Indeed, I never said there was anything wrong with the way it was coded. It just didn't jump out at me as something all that complicated. But, that could just be me
Quote:
|
Exceptions can be handled in the same manner as any other error and in such a way to be passed to a view.
|
The framework does handle exceptions already. Again you are making assumptions about something you haven't even seen.
Quote:
|
I was not being rude to you at any point ... if this is how you see it, I'm sorry you cannot take it.
|
I see it as it is presented to me. Saying things like "...with no understanding of how they work ... I wish you Good luck." and "but I do not see any potential for me to even consider downloading" is very rude.
|
|
|
|
07-30-2009, 03:12 PM
|
#82 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
|
Quote:
|
The way errors are handled can be modified by editing the error view files. Critical errors will always stop execution of the PHP script and remove anything in the output buffer (besides what the error view puts in it).
|
Quote:
|
The framework does handle exceptions already. Again you are making assumptions about something you haven't even seen.
|
I based this information on what you have stated, errors and exceptions are 2 completely separate things. You said Critical errors always stop execution I assumed you were talking about exception as "critical errors".
|
|
|
|
07-30-2009, 05:18 PM
|
#83 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Fair enough.
Here's sneak peak of what I'm planning to do with database selects:
PHP Code:
$table = $this->db->select_table('users');
$select = $table->select(); $select->column('*'); $select->where('name','=','Joe'); $select->order('name'); $data = $table->execute($select);
Of coarse you will still be able to do this:
PHP Code:
$data = $this->db->query("SELECT * FROM `users` WHERE `name`='Joe' ORDER BY `name`");
Expect similar syntax for other kinds of queries as well. Any comments, likes, or dislikes?
Last edited by ETbyrne : 07-30-2009 at 05:54 PM.
|
|
|
|
07-31-2009, 08:06 PM
|
#84 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by ETbyrne
Fair enough.
Here's sneak peak of what I'm planning to do with database selects:
PHP Code:
$table = $this->db->select_table('users');
$select = $table->select(); $select->column('*'); $select->where('name','=','Joe'); $select->order('name'); $data = $table->execute($select);
Of coarse you will still be able to do this:
PHP Code:
$data = $this->db->query("SELECT * FROM `users` WHERE `name`='Joe' ORDER BY `name`");
Expect similar syntax for other kinds of queries as well. Any comments, likes, or dislikes?
|
Why complicate it?
What's wrong with this?
php Code:
$this-> db-> table('users') -> select(array('col', 'col', 'col')) -> where('name', 'Joe') -> order_by('name', 'DESC'); $q = $this-> db-> get(); // or execute() or w.e you wanna call it
__________________
|
|
|
|
07-31-2009, 08:45 PM
|
#85 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
But what happens if you want to only select the rows where name != Joe? Or perhaps you want to order your results by name and then id (just in case two people have the same name)? With my method you can do those things:
PHP Code:
$table = $this->db->select_table('users');
$select = $table->select(); $select->column('*'); $select->where('name','!=','Joe'); $select->order('name'); $select->order('id'); $select->desc(); $data = $table->execute($select);
Of coarse we could probably combine the two to make a more elegant solution:
PHP Code:
$table = $this->db->table('users');
$table->select() ->column('*') ->where('name','!=','Joe') ->order('name') ->order('id') ->desc();
$data = $table->execute();
But idk this looks like it's starting to get messy on that first line:
PHP Code:
$this->db->table('users')->select() ->column('*') ->where('name','!=','Joe') ->order('name') ->order('id') ->desc();
$data = $this->db->execute();
|
|
|
|
07-31-2009, 10:07 PM
|
#86 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Or wait this may even be better:
PHP Code:
$table = $this->db->table('users');
$data = $table->select() ->column('*') ->where('name','!=','Joe') ->order('name') ->order('id') ->desc() ->execute();
Or even:
PHP Code:
$query = $table->select() ->column('*') ->where('name','!=','Joe') ->order('name') ->order('id') ->desc();
$data = $table->execute($query);
The above would actually make it so I wouldn't have as much code duplication among database drivers, but it also takes more typing. What do you think?
Last edited by ETbyrne : 07-31-2009 at 10:37 PM.
|
|
|
|
08-01-2009, 12:59 AM
|
#87 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Never mind, I've already implemented the last two examples in addition to the original! So there are three slightly different ways you can construct a SELECT query now:
PHP Code:
$data = $table->select() ->column('*') ->where('name','!=','Joe') ->order('name') ->order('id') ->desc() ->execute();
PHP Code:
$query = $table->select() ->column('*') ->where('name','!=','Joe') ->order('name') ->order('id') ->desc();
$data = $table->execute($query);
PHP Code:
$select = $table->select(); $select->column('*'); $select->where('name','!=','Joe'); $select->order('name'); $select->order('id'); $select->desc(); $data = $table->execute($select);
All of the above return the exact same results. I personally like the first one the most as it uses the least amount of code. For that reason it will probably be the first example given in the docs for these types of queries.
Btw INSERTS are done like so:
PHP Code:
$table->insert(array( 'user'=>'Mary', 'friend'=>'Joe' ));
The script automatically cleans the values 'Mary' and 'Joe'. Same goes for the value 'Joe' in the SELECT examples.
|
|
|
|
08-01-2009, 02:55 PM
|
#88 (permalink)
|
|
The Contributor
Join Date: Mar 2009
Location: US
Posts: 76
Thanks: 0
|
It would be much easier to do something such as
php Code:
$data = $table->select('col1', 'col2', 'col3') ->where('name', '-Joe', 'id', '>20') ->order('name', '-id') ->exec();
You would be able to use to get the names of the columns, same could go for the order and where clause.
The " - " and " > " are used as type hinting to achieve the same result as adding an additional parameter.
Making it much easier for the end user
|
|
|
|
08-01-2009, 03:37 PM
|
#89 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
|
I don't want to just throw another idea into the mix but I'm not a fan of any of the methods show in the last few posts; they all seem a little muddled or not particularly user friendly.
Having methods like desc() doesn't make sense to me, the direction only makes sense for ORDER BY so why separate it? The select method seems redundant if the columns have to be specified separately: why not select($columns) (an array of column names)?
It's all well and good being flexible but if the same thing can be done twenty different ways (all of which are specific to your framework) then that's not being flexible: it's creating a headache.
|
|
|
|
08-01-2009, 04:08 PM
|
#90 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
@ioan1k, that's an interesting idea I'll definitely look into that.
@Salathe, I could add the $columns argument to the select() method, that would be really easy to do.
The thing is with mixing the ORDER BY method with the DESC method is that what if you happen to have a table column named "desc"? I know that's very unlikely to happen but I'm trying to keep it as straight forward as possible without creating any design limitations.
The same thing goes for ioan1k's idea of putting the "-" and ">" in with the value, what if you had some data that started with a ">" or a "-"? Not only does it impose design limitations and add to the complexity of the driver, it also opens the system up to new kinds of SQL injection.
I think that something like this should be simple enough for the developer to understand:
PHP Code:
$data = $table->select('col1','col2','col3') ->where('name','!=','Joe') ->order('name','id') ->desc() ->execute();
Also, it just so happened that with the way the driver was built that it allowed all three of those methods to work. I'm not planning on throwing all of them at the user.
|
|
|
|
08-01-2009, 04:15 PM
|
#91 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Here's a function I developed for my MySQL_Helper class.
php Code:
/* |-------------------------------------------------------------------------- | __where |-------------------------------------------------------------------------- | | Gets the "WHERE" -part when constructing a delete, update or select query | */ private function __where () { if(isset($this-> where) && ! empty($this-> where)) { $sql = 'WHERE '; $i = 0; foreach($this-> where as $col => $value) { if($i != 0) { $sql .= 'AND '; } $sql .= $this->__backtick ($col) . ' '; if(is_array($value)) { $sql .= $value[ 'operator'] . ' ' . $this->__tick ($value[ 'value'] ) . ' '; } else { $sql .= '= ' . $this->__tick ($value) . ' '; } $i++; } $this-> sql .= $sql; } }
That will take care of your != problem.
PHP Code:
$this->db->table('users') ->select(array('col', 'col', 'col')) ->where('name', array('operator' => '!=', 'value' => 'Joe') ->order_by('name', 'DESC') ->order_by('id', 'ASC');
$q = $this->db->get(); if($q->num_rows() > 0) { // do something }
Here's the order_by function:
php Code:
/* |-------------------------------------------------------------------------- | __order_by |-------------------------------------------------------------------------- | | Gets the "ORDER BY" -part when constructing a select query | */ private function __order_by () { if(isset($this-> order_by) && ! empty($this-> order_by)) { $sql = 'ORDER BY '; $i = 0; foreach($this-> order_by as $order => $how) { if($i != 0) { $sql .= 'AND '; } $sql .= $this->__backtick ($order) . ' ' . $how . ' '; $i++; } $this-> sql .= $sql; } }
Would give you this:
Code:
SELECT `col`, `col`, `col` FROM `users` WHERE `name` != 'Joe' ORDER BY `name` DESC AND `id` ASC;
__________________
|
|
|
|
08-01-2009, 04:27 PM
|
#92 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Ah now I see what you mean by the order_by() method! I thought you meant something like:
PHP Code:
->order_by('col1','col2','DESC')
But that example cleared things up much better for me and I think you're right with the order_by() method. Although the WHERE one seems a bit over complicated to me.
|
|
|
|
08-01-2009, 05:48 PM
|
#93 (permalink)
|
|
Moderateur
Join Date: Apr 2007
Posts: 1,381
Thanks: 5
|
Quote:
Originally Posted by ETbyrne
The thing is with mixing the ORDER BY method with the DESC method is that what if you happen to have a table column named "desc"?
|
That's a complete non-issue if your class wraps db/table/column names with backticks. SELECT * FROM blah ORDER BY `desc` DESC What's stopping anyone from asking for a "restricted identifier" through the other class methods already (eg. ->columns("desc")). Backtick quoting will also help you should someone decided to use any of these words where perhaps they shouldn't.
|
|
|
|
08-01-2009, 06:56 PM
|
#94 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Oh wait I'm sorry Salathe, I got you confused with Tanax... Yeah my last comment was geared towards kind of both of you. The issue I was having was I thought that tanax's order_by() method would be used like this:
PHP Code:
->order_by('col1','col2','DESC');
Which was not correct, I was supposed to use it like this:
PHP Code:
->order_by('col1','DESC'); ->order_by('col2','ASC');
Tanax's post cleared that up for me. It's no longer an issue.
|
|
|
|
08-01-2009, 06:57 PM
|
#95 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
sorry, double post...
|
|
|
|
08-03-2009, 03:48 PM
|
#96 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Just added UPDATE and DELETE functions to the database driver:
PHP Code:
$table->update(array('friend'=>'Joe')) ->where('friend','=','Joe Momma') ->execute();
$table->delete() ->where('user','=','Mary') ->execute();
I'm thinking about making it so that the DELETE will also work like this:
PHP Code:
$table->delete('user','=','Mary');
Of coarse that would only work for simple deletes.
EDIT: Shorthand DELETE and SELECT added.
PHP Code:
$data = $table->select('col','=','value'); print_r($data);
$table->delete('col','=','value');
Last edited by ETbyrne : 08-03-2009 at 04:37 PM.
|
|
|
|
09-03-2009, 07:14 PM
|
#97 (permalink)
|
|
how quixotic are you?
Join Date: Dec 2007
Location: Lapeer, MI
Posts: 445
Thanks: 37
|
Release date for dingo has been set to October 1st. Many things have been added to the framework since the public ALPHA, including...
ACL Library
XML Safe Serializing / De-serializing (does not ruin HTML)
XSS filtering (restrictive filter, not permissive)
Pagination Helper
RSS Helper
More traditional Model implementation (figured it would be less confusing)
PostgreSQL Database Driver
Session Handling Library
Plus many other small improvements. Hope you all like it when it comes out! 
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|