-
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
Conversation
This is the collection of guidelines for database work. futher information can be found here owncloud-archive/documentation#3805
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.
Looks good, see two optional changes
** 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 | ||
* 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
s/, it is/, as it is/g
* 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 | ||
** Keep this in mind when designing DB schema and values expectations. |
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.
I think you can remove this line
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.
Alternatively, it could be added as a lead-in sentence above the list.
** 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 | ||
* Always add the table name when calling `lastInsertId($tableName)`, it is required by Oracle to return correct values | ||
* 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 comment
The 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 autoincrement
column. If you have to, keep in mind that Oracle's autoincrement
trigger will get in the way on INSERT
. As a result, you'll need a subsequent UPDATE
to properly adjust the value.
** 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 | ||
* Always add the table name when calling `lastInsertId($tableName)`, it is required by Oracle to return correct values | ||
* 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 | ||
* *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 comment
The 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.
* *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 | ||
* 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 comment
The reason will be displayed to describe this comment to others. Learn more.
s/Mysql/MySQL/g
* 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 | ||
** `str1 || str1 ... || strN` Sqlite/PgSQL/Oracle |
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/Sqlite/SQLite/g
s/PgSQL/pgSQL/g
* 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 |
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
* 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 comment
The 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. | ||
** 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 comment
The reason will be displayed to describe this comment to others. Learn more.
s/the escaping/The escaping/g
"otherwise", at the end of the second sentence seems superfluous.
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.
I realise that my review may seem quite nitpicky, but the changes are worth making. In addition, please end all bullet points with a period.
@voroyam, thanks for making the final changes. |
This is the collection of guidelines for database work.
futher information can be found here
owncloud-archive/documentation#3805