Code Monkey home page Code Monkey logo

Comments (10)

pmjones avatar pmjones commented on August 23, 2024

So the issue is, if somebody does this ...

$select->from('table_name');
$result = $sql->query($select);

... then it fails, because they didn't specify any cols to retrieve.

Although it seems harmless, I don't think we should set a default for that. My fear is that it could get in the way of some kinds of rare but necessary queries, but I don't have any proof for that.

We can point out in the documentation how to debug that kind of problem, though. Would that help?

from aura.sql.

harikt avatar harikt commented on August 23, 2024

Can we throw an exception stating the reason, when cols is empty ?

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

I get the idea there may be times when cols is supposed to be empty, but I don't know. Is the error not obvious when it occurs?

from aura.sql.

harikt avatar harikt commented on August 23, 2024

@pmjones I will check . Before this I am testing the closed issues which seems not really resolved. I will open it .

from aura.sql.

harikt avatar harikt commented on August 23, 2024

This was what I was trying earlier

$select = new Aura\Sql\Select($sql);
$select->from('posts');
$result = $sql->fetchOne($select);
var_export($result);

When column is not given error is

SELECT
PHP Fatal error:  Uncaught exception 'Aura\Autoload\Exception\NotReadable' with message 'Aura\Sql\Select
#0: /media/Linux/aurasystem/package/Aura.Sql/src
#1.:/usr/share/php:/usr/share/pear' in /media/Linux/aurasystem/package/Aura.Autoload/src/Aura/Autoload/Loader.php:317
Stack trace:
#0 [internal function]: Aura\Autoload\Loader->load('Aura\Sql\Select')
#1 /media/Linux/auracomponentstest/select.php(26): spl_autoload_call('Aura\Sql\Select')
#2 {main}
  thrown in /media/Linux/aurasystem/package/Aura.Autoload/src/Aura/Autoload/Loader.php on line 317

Obviously nothing there to figure out right ?

When table name is not given , error below

$select = new Aura\Sql\Select($sql);
$select->cols(array('id', 'author_id', 'title', 'body'));
$result = $sql->fetchOne($select);
var_export($result);

Which I got the errors as below

PHP Fatal error:  Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list'' in /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Profiler.php:82
Stack trace:
#0 /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Profiler.php(82): PDOStatement->execute()
#1 /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Adapter/AbstractAdapter.php(282): Aura\Sql\Profiler->exec(Object(PDOStatement), Array)
#2 /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Adapter/AbstractAdapter.php(547): Aura\Sql\Adapter\AbstractAdapter->query(Object(Aura\Sql\Select), Array)
#3 /media/Linux/auracomponentstest/select.php(29): Aura\Sql\Adapter\AbstractAdapter->fetchOne(Object(Aura\Sql\Select))
#4 {main}
  thrown in /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Profiler.php on line 82

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42S22]: Column not found: 1054 Unknown column 'id' in 'field list'' in /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Profiler.php:82
Stack trace:
#0 /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Profiler.php(82): PDOStatement->execute()
#1 /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Adapter/AbstractAdapter.php(282): Aura\Sql\Profiler->exec(Object(PDOStatement), Array)
#2 /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Adapter/AbstractAdapter.php(547): Aura\Sql\Adapter\AbstractAdapter->query(Object(Aura\Sql\Select), Array)
#3 /media/Linux/auracomponentstest/select.php(29): Aura\Sql\Adapter\AbstractAdapter->fetchOne(Object(Aura\Sql\Select))
#4 {main}
  thrown in /media/Linux/aurasystem/package/Aura.Sql/src/Aura/Sql/Profiler.php on line 8

from aura.sql.

harikt avatar harikt commented on August 23, 2024

I have modified the comments with the latest errors thrown.

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

I don't think this is that big a deal, but even so, what do you suggest as the remedy?

from aura.sql.

harikt avatar harikt commented on August 23, 2024

What my suggestion is if no fields or table name found lets throw a meaningful exception

from aura.sql.

pmjones avatar pmjones commented on August 23, 2024

Technically, you don't always need a table name. For example, you can issue SELECT NOW() and it works just fine.

After thinking about this for a long time, I realize I'd rather not get into checking SQL syntax in the PHP; if the developer gets it wrong, he'll be notified by the database. PDO will throw an exception with everything you need to diagnose the failure.

from aura.sql.

harikt avatar harikt commented on August 23, 2024

ok :)

from aura.sql.

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.