Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  Update changelog
  Issue #12: Fix incorrect quoting of column wildcard. Thanks pewterfish.
  Add MySQL-specific connection example in README
  Fix out-of-date comment and typo in README
  • Loading branch information
j4mie committed Jan 30, 2011
2 parents d06ff35 + c5c67a3 commit c956f1c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 15 additions & 3 deletions README.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ Changelog
* Add `distinct` method
* Add `group_by` method

#### 1.1.1 - release 2011-01-30

* Fix bug in quoting column wildcard. j4mie/paris#12
* Small documentation improvements

Philosophy
----------

Expand All @@ -58,10 +63,17 @@ First, `require` the Idiorm source file:

require_once 'idiorm.php';

Then, pass a *Data Source Name* connection string to the `configure` method of the ORM class. This is used by PDO to connect to your database. For more information, see the [PDO documentation](http://uk2.php.net/manual/en/pdo.construct.php). Particularly, if you need to pass a username and password to your database driver, use the `username` and `password` configuration options. See "Configuration" section below.

Then, pass a *Data Source Name* connection string to the `configure` method of the ORM class. This is used by PDO to connect to your database. For more information, see the [PDO documentation](http://uk2.php.net/manual/en/pdo.construct.php).
ORM::configure('sqlite:./example.db');

You may also need to pass a username and password to your database driver, using the `username` and `password` configuration options. For example, if you are using MySQL:

ORM::configure('mysql:host=localhost;dbname=my_database');
ORM::configure('username', 'database_user');
ORM::configure('password', 'top_secret');

Also see "Configuration" section below.

### Querying ###

Idiorm provides a [*fluent interface*](http://en.wikipedia.org/wiki/Fluent_interface) to enable simple queries to be built without writing a single character of SQL. If you've used [jQuery](http://jquery.com) at all, you'll be familiar with the concept of a fluent interface. It just means that you can *chain* method calls together, one after another. This can make your code more readable, as the method calls strung together in order can start to look a bit like a sentence.
Expand Down Expand Up @@ -116,7 +128,7 @@ Only a subset of the available conditions supported by SQL are available when us

These limits are deliberate: these are by far the most commonly used criteria, and by avoiding support for very complex queries, the Idiorm codebase can remain small and simple.

Some support for more complex conditions and queries is provided by the `where_raw` and `raw_select` methods (see below). If you find yourself regularly requiring more functionality than Idiorm can provide, it may be time to consider using a more full-featured ORM.
Some support for more complex conditions and queries is provided by the `where_raw` and `raw_query` methods (see below). If you find yourself regularly requiring more functionality than Idiorm can provide, it may be time to consider using a more full-featured ORM.

##### Equality: `where`, `where_equal`, `where_not_equal` #####

Expand Down
7 changes: 5 additions & 2 deletions idiorm.php
Original file line number Diff line number Diff line change
Expand Up @@ -899,10 +899,13 @@ protected function _quote_identifier($identifier) {

/**
* This method performs the actual quoting of a single
* part of an identifier. Currently uses backticks, which
* are compatible with (at least) MySQL and SQLite.
* part of an identifier, using the identifier quote
* character specified in the config (or autodetected).
*/
protected function _quote_identifier_part($part) {
if ($part === '*') {
return $part;
}
$quote_character = self::$_config['identifier_quote_character'];
return $quote_character . $part . $quote_character;
}
Expand Down
8 changes: 8 additions & 0 deletions test/test_queries.php
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@
$expected = "DELETE FROM `widget` WHERE `id` = '1'";
Tester::check_equal("Delete data", $expected);

// Regression tests

$widget = ORM::for_table('widget')->select('widget.*')->find_one();
$expected = "SELECT `widget`.* FROM `widget` LIMIT 1";
Tester::check_equal("Issue #12 - incorrect quoting of column wildcard", $expected);

// Tests that alter Idiorm's config are done last

ORM::configure('id_column', 'primary_key');
ORM::for_table('widget')->find_one(5);
$expected = "SELECT * FROM `widget` WHERE `primary_key` = '5' LIMIT 1";
Expand Down

0 comments on commit c956f1c

Please sign in to comment.