Comments (9)
Comment created by @beberlei:
Discussions on the API:
First observations/requirements:
- Identifiers are NEVER quoted by the SQL Query Object
- A query object cannot ever be as efficient as our Persisters building SQL in a custom way
- A SQL Query instance is only an Object with an internal stack of SQL parts, it should not have any logic whatsoever
- A SQL Query instance is a stack for bound params and values, i.e. it should work towards prepared statements and not inline and quote values (like Zend_Db_Select)
Questions:
- Should we allow methods to accept either array or string? Or streamline API to allow only one? select(string) + selectAll(array)?
Binding values:
$sql->bindValue(1); // adds 1 to the bind stack and returns a ":doctrineValue$inc" string
$sql->bindParam($foo, PDO::PARAM_INT); // the same as before, with additional type binding
Building a Select clause A:
$sql->select(array('foo', 'bar', 'baz')); // SELECT foo, bar, baz
$sql->select(array('foo' => 'foo1', 'bar' => 'bar2', 'baz' => 'baz3')); // SELECT foo AS foo1, bar AS bar2, baz AS baz3
Building a Select clause B:
$sql->select('foo')->select('bar')->select('baz'); // SELECT foo, bar, baz
$sql->select('foo', 'f'); // SELECT foo AS f
Building the From clause A:
$sql->from('foo'); // FROM foo
$sql->from('foo', 'f'); // FROM foo f
$sql->from('foo', 'f', array('foo')); // SELECT foo FROM foo f
Building the From Clause B:
$sql->from('foo'); // FROM foo
$sql->from(array('foo')); // FROM foo
$sql->from(array('f' => 'foo')); // FROM foo f
$sql->from(array('f' => 'foo'), array('foo')); // SELECT foo FROM foo f
Building a Join clause (obviously depends on the From syntax also for a consistent approach):
public function join($table, $alias, $onClause, $cols);
public function join($table, $onClause, $cols);
Join Method Names: joinInner, joinLeft, joinRight (Zend) OR innerJoin, leftJoin, rightJoin (Zeta)?
Where Syntax:
This is pretty difficult and i prefer the approach from ORM\QueryBuilder:
$sql->where("foo = ?");
$sql->where("foo = ?", $foo); // allow this? its Zend*Db*Select syntax
$sql->where("foo = " . $sql->bindParam($foo));
$sql->where($sql->expr()->eq("foo", $sql->bindParam($foo));
For an OR on the main level:
$sql->where("foo = ?")->orWhere("bar = ?");
For a nested condition:
$sql->where("foo = ? OR bar = ? OR baz = ?");
$sql->where($sql->expr()->or(
$sql->expr()->eq("foo", $sql->bindParam($foo)),
$sql->expr()->eq("bar", $sql->bindParam($bar)),
$sql->expr()->eq("baz", $sql->bindParam($baz)),
));
There is an Expression class that has control flow and sql functions, using a platform internally for vendor specific sql.
Execution or Preparing the SQL:
$stmt = $sql->prepare();
$sql->execute();
Comments?
from dbal.
Comment created by romanb:
The usage of bindValue/bindParam is very confusing to me. It should be in-line with PDO where the only difference is whether the parameter is bound by value (the value of the variable gets bound at the point of the method call) or by reference (the value of the variable gets bound at the point the statement is executed).
from dbal.
Comment created by @beberlei:
How would that look like in your opinion? This is what Zend_Db_Select gets wrong...
from dbal.
Comment created by romanb:
Well I would say either having bindValue/bindParam but with the same semantics as PDO or trashing both and just having setParameter, like we do in the ORM, that binds the value at the time of the invocation, intuitively.
I would go with the latter as I have yet to find a real use-case for bindParam (binding "by reference").
The only "wrong" direction here IMHO is to reuse PDOs names but give them a completely different meaning.
I would just go with setParameter($key, $value, [$type = PDO::PARAM_STR]).
I might be missing something though because I dont really understand the bindValue/bindParam examples given in your comments, i.e. I dont understand why it "generates" a key. Can you show a "real" example usage in a query?
from dbal.
Comment created by @beberlei:
But how would that bind stuff work with sub selects?
Say you do:
$sub = new SelectQuery();
$sub->select('a')->from('subtable')->where('b = ?')
$root = new SelectQuery();
$root->select('b')->from('root')->where('b IN (' . $sub . ' )');
from dbal.
Comment created by @beberlei:
Assigned to Guilherme for 2.1
from dbal.
Comment created by @beberlei:
Implemented
from dbal.
Issue was closed with resolution "Fixed"
from dbal.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
from dbal.
Related Issues (20)
- Column precision is not specified
- Support DuckDB HOT 1
- [API] Add getWrappedDriver method to AbstractDriverMiddleware HOT 2
- Doctrine\ORM\QueryBuilder::setParameter and ArrayParameterType in 4.0.0 HOT 2
- `SqliteSchemaManager` still emulates schema namespacing
- Custom driver and ExceptionConverter HOT 1
- PostgreSQL option gssencmode=disable isn't configurable HOT 4
- index-by and order-by do not work for abstract entities with inheritance type "JOINED" in many-to-many relations HOT 3
- Got error on SQLite database creation stage HOT 7
- Incorrect definition of table mysql.column_stats MariaDB OOM-kill HOT 3
- Mysqli Driver - Undesired Collations Cannot be Altered for `collation_connection` Variable
- Platform override HOT 4
- "dbal:run-sql command does not correctly output query results, shows '0 rows affected' instead" HOT 3
- PostgreSQLSchemaManager does not resolve single-quote quoting when retrieving schema information
- COLLATION_CHARACTER_SET_APPLICABILITY.COLLATION_NAME vs MariaDB FULL_COLLATION_NAME HOT 3
- Facing issue when trying to use old database (CORE PHP) with new symfony APP. HOT 1
- ❓ Is there a DBAL constant or similar to easily find which major version is installed? HOT 1
- Basic `UNION` support for the `QueryBuilder`
- [4.0] Query builder - how to reset `From` query part? HOT 9
- sql rename table :old_table to :new_table not working parameterised HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dbal.