phpixie / database Goto Github PK
View Code? Open in Web Editor NEWPHPixie Database Library
License: BSD 3-Clause "New" or "Revised" License
PHPixie Database Library
License: BSD 3-Clause "New" or "Revised" License
Hi @dorantor, would you please add solr driver?
I came across a problem using functions with this component. The SQL query I'd like to execute:
SELECT md5(random()::text || clock_timestamp()::text)::uuid
When using the component I end up with the following:
$result = $query
->table('pg_language')
->fields(array(
'md5(random()::text || clock_timestamp()::text)::uuid'
))
->execute();
// Query: SELECT "md5(random()::text || clock_timestamp()::text)::uuid"
// The field will be handled as a column name and ends up in an error
I created an ugly workaround to achieve my goal:
$result = $query
->table('pg_language')
->fields(array(
'lanname", md5(random()::text || clock_timestamp()::text)::uuid AS UUID, "lanowner'
))
->execute();
// Query: SELECT "lanname", md5(random()::text || clock_timestamp()::text)::uuid AS UUID, "lanowner" FROM "pg_language"
I recommend to add a new function like fields
but name it unescapedFields
or something.
Assume you want to query mytable
of the following database structure:
mydatabase
⌙-> myschema
⌙-> mytable
A general query would look like this (given that you selected the database):
SELECT * FROM "myschema"."mytable";
Translating it to the Database
component:
$gateways = $query
->table('myschema.mytable');
/*
execute():
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42P01]: Undefined table: 7 ERROR: relation "myschema.mytable" does not exist LINE 1: SELECT * FROM "myschema.mytable" ^' in ...
parse():
object(PHPixie\Database\Type\SQL\Expression)#51 (2) { ["sql"]=> string(28) "SELECT * FROM "myschema.mytable"" ["params"]=> array(0) { } }
SQL Query:
SELECT * FROM "myschema.mytable" // invalid
*/
$gateways = $query
->table('"myschema"."mytable"');
/*
execute():
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42601]: Syntax error: 7 ERROR: zero-length delimited identifier at or near """" LINE 1: SELECT * FROM ""myschema"."mytable"" ^' in
parse():
object(PHPixie\Database\Type\SQL\Expression)#51 (2) { ["sql"]=> string(32) "SELECT * FROM ""myschema"."mytable""" ["params"]=> array(0) { } }
SQL Query:
SELECT * FROM ""myschema"."mytable"" // invalid
*/
For a correct escaping I have to write the table like this: myschema"."mytable
because the component just adds a double quote at the beginning and at the end of the table definition.
$query = $connection->selectQuery();
$gateways = $query
->table('myschema"."mytable');
parse():
object(PHPixie\Database\Type\SQL\Expression)#51 (2) { ["sql"]=> string(30) "SELECT * FROM "myschema"."mytable"" ["params"]=> array(0) { } }
SQL Query:
SELECT * FROM "myschema"."mytable" // valid
I suggest to escape the table like this:
explode
table by .
(dot)implode
components by .
(dot)This would also work for MySQL, where you can query by mydatabase.mytable
If you create a INSERT query like it's described in the README.md it won't work:
// Inserting
$insertQuery = $connection->insertQuery();
$insertQuery->data(
'id' => 1,
'title' => 'Hello'
)->execute();
It seems like the array()
was forgotten.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.