-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
database guidelines #71
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -42,6 +42,29 @@ class AuthorDAO { | |
} | ||
---- | ||
|
||
Database programming guidelines | ||
------------------------------- | ||
|
||
* Always use the Query Builder | ||
* Don't update more than 1 million rows within a transaction due to DB limitations | ||
* Don't add more than 999 conditions in a `WHERE ... IN ...` statement but chunk it into separate queries when using SQLite | ||
* When processing big tables, always do this in chunks, don't store the whole table in memory | ||
* Oracle compatibility specifics: | ||
** For Oracle `null` and empty strings are the same thing. Need special handling to catch these cases | ||
** When reading values, make sure to convert null to empty string when expected | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/convert null to empty string/convert nulls to empty strings/g |
||
** Keep this in mind when designing DB schema and values expectations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can remove this line There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Alternatively, it could be added as a lead-in sentence above the list. |
||
** When using a condition based on empty strings, use `is not null` with Oracle instead | ||
** Oracle can only compare the first 4000 bytes of a `CLOB` column | ||
** Make sure to properly escape column names when using custom functions with `createFunction`. the escaping is usually done automatically by the query builder otherwise. Oracle is the most likely to complain about unquoted columns while other databases will work fine | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/the escaping/The escaping/g |
||
* Always add the table name when calling `lastInsertId($tableName)`, it is required by Oracle to return correct values | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add a second "*" as this belongs to the Oracle block There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/, it is/, as it is/g |
||
* In general don't specify a value for autoincrement column. if you have to, keep in mind that Oracle's autoincrement trigger will get in the way on `INSERT`, so you'll need a subsequent `UPDATE` to properly adjust the value | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd rewrite this as: In general, don't specify a value for an |
||
* *Always* make sure there are unit tests for the database operations with queries to verify the result, this will help find out whether the database related code works on all databases and often times might reveal database quirks | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Break this sentence into two, with the second sentence starting at "this will". It makes it easier to read and digest. |
||
* Running unit tests with specific databases: `make test-php TEST_PHP_SUITE=path/to/test/file.php TEST_DATABASE=$databasetype` where "$databasetype" is one of "sqlite", "mysql", "mariadb", "pgsql", "oci" and "mysqlmb4" | ||
* String concatenation should be done like this: | ||
** `CONCAT(str1, str2, ... strN)` for Mysql | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Mysql/MySQL/g |
||
** `str1 || str1 ... || strN` Sqlite/PgSQL/Oracle | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/Sqlite/SQLite/g |
||
* Use `IQueryBuilder::createPositionalParameter` instead of `IQueryBuilder::createNamedParameter` when using `like()` | ||
|
||
[[mappers]] | ||
Mappers | ||
------- | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/For Oracle/For Oracle,/g
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/Need special handling/Special handling is required/g