Coder Social home page Coder Social logo

Comments (9)

doctrinebot avatar doctrinebot commented on May 17, 2024

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.

doctrinebot avatar doctrinebot commented on May 17, 2024

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.

doctrinebot avatar doctrinebot commented on May 17, 2024

Comment created by @beberlei:

How would that look like in your opinion? This is what Zend_Db_Select gets wrong...

from dbal.

doctrinebot avatar doctrinebot commented on May 17, 2024

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.

doctrinebot avatar doctrinebot commented on May 17, 2024

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.

doctrinebot avatar doctrinebot commented on May 17, 2024

Comment created by @beberlei:

Assigned to Guilherme for 2.1

from dbal.

doctrinebot avatar doctrinebot commented on May 17, 2024

Comment created by @beberlei:

Implemented

from dbal.

doctrinebot avatar doctrinebot commented on May 17, 2024

Issue was closed with resolution "Fixed"

from dbal.

github-actions avatar github-actions commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.