Comments (10)
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.
Can we throw an exception stating the reason, when cols is empty ?
from aura.sql.
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.
@pmjones I will check . Before this I am testing the closed issues which seems not really resolved. I will open it .
from aura.sql.
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.
I have modified the comments with the latest errors thrown.
from aura.sql.
I don't think this is that big a deal, but even so, what do you suggest as the remedy?
from aura.sql.
What my suggestion is if no fields or table name found lets throw a meaningful exception
from aura.sql.
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.
ok :)
from aura.sql.
Related Issues (20)
- Bug with pgsql query HOT 5
- DB Reconnection HOT 5
- Auto adding Ticks HOT 8
- Decode json? (to arrays) HOT 1
- Bug in Queryparser for SQLite HOT 3
- Question HOT 1
- Using 2.x and 3.x in parallel HOT 10
- What is the future of this project? HOT 15
- Create GIthub Actions to automatically build and test this package
- PHP 8.1 Compatibility HOT 8
- Type hint incomplete HOT 7
- Scrutinizer Error HOT 1
- Version that doesn't throw deprecation warnings in 8.1 but works in 8.0? HOT 19
- Works with all versions of PHP from 5.6 to 8.1
- Release note HOT 7
- Abandon 4.x ? HOT 2
- Consider tagging / releasing 3.0.1 please ? HOT 2
- How to debug "Column count doesn't match value count"? HOT 1
- Time for 5.0.2/5.1 HOT 4
- Does Aura.Sql suffer of the problem of useless order by on some ORM prefetches ? HOT 2
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 aura.sql.