Skip to content
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

Merged
merged 5 commits into from
Sep 13, 2018
Merged

database guidelines #71

merged 5 commits into from
Sep 13, 2018

Conversation

voroyam
Copy link
Contributor

@voroyam voroyam commented Sep 7, 2018

This is the collection of guidelines for database work.

futher information can be found here

owncloud-archive/documentation#3805

This is the collection of guidelines for database work.

futher information can be found here

owncloud-archive/documentation#3805
Copy link
Contributor

@PVince81 PVince81 left a 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
Copy link
Contributor

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

Copy link
Contributor

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.
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

@settermjd settermjd Sep 12, 2018

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
Copy link
Contributor

@settermjd settermjd Sep 12, 2018

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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

Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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.

Copy link
Contributor

@settermjd settermjd left a 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.

@settermjd settermjd added enhancement New feature or request work in progress Still in development. Not to be merged. labels Sep 12, 2018
@settermjd
Copy link
Contributor

@voroyam, thanks for making the final changes.

@settermjd settermjd merged commit 454f5c7 into master Sep 13, 2018
@settermjd settermjd deleted the database-guidelines branch September 13, 2018 07:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request work in progress Still in development. Not to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants