Browse Source

Merge pull request #4284 from nocodb/fix/default-db-collation

Set default database encoding/charset to utf8
pull/4231/head
mertmit 2 years ago committed by GitHub
parent
commit
b17fc9ce39
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nocodb/src/lib/db/sql-client/lib/mysql/mysql.queries.ts
  2. 2
      packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts
  3. 18
      packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

2
packages/nocodb/src/lib/db/sql-client/lib/mysql/mysql.queries.ts

@ -130,7 +130,7 @@ AND t.table_name=?;`,
},
createDatabaseIfNotExists: {
default: {
sql: `create database if not exists ??`,
sql: `create database if not exists ?? CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci`,
paramsHints: ['database'],
},
},

2
packages/nocodb/src/lib/db/sql-client/lib/pg/PgClient.ts

@ -468,7 +468,7 @@ class PGClient extends KnexClient {
}
if (rows.length === 0) {
log.debug('creating database:', args);
await tempSqlClient.raw(`CREATE DATABASE ??`, [args.database]);
await tempSqlClient.raw(`CREATE DATABASE ?? ENCODING 'UTF8'`, [args.database]);
}
// if (this.connectionConfig.searchPath && this.connectionConfig.searchPath[0]) {

18
packages/nocodb/src/lib/db/sql-client/lib/sqlite/SqliteClient.ts

@ -7,11 +7,13 @@ import Result from '../../../util/Result';
import queries from './sqlite.queries';
import lodash from 'lodash';
import _ from 'lodash';
const log = new Debug('SqliteClient');
class SqliteClient extends KnexClient {
private queries: any;
private _version: any;
constructor(connectionConfig) {
super(connectionConfig);
this.sqlClient = knex(connectionConfig.connection);
@ -130,10 +132,14 @@ class SqliteClient extends KnexClient {
const fd = await promisify(fs.open)(args.database, 'w');
const close = await promisify(fs.close)(fd);
log.debug('sqlite file is created', fd, close);
// create new knex client
this.sqlClient = knex(this.connectionConfig.connection);
// set encoding to utf8
await this.sqlClient.raw('PRAGMA encoding = "UTF-8"');
} else {
// create new knex client
this.sqlClient = knex(this.connectionConfig.connection);
}
// create new knex client
this.sqlClient = knex(this.connectionConfig.connection);
} catch (e) {
log.ppe(e, _func);
throw e;
@ -277,7 +283,7 @@ class SqliteClient extends KnexClient {
* @property {String} - tables[].tn
*/
async tableList(args: any = {}) {
const _func = this.createDatabaseIfNotExists.name;
const _func = this.tableList.name;
const result = new Result();
log.api(`${_func}:args:`, args);
@ -305,7 +311,7 @@ class SqliteClient extends KnexClient {
}
async schemaList(args: any = {}) {
const _func = this.createDatabaseIfNotExists.name;
const _func = this.schemaList.name;
const result = new Result();
log.api(`${_func}:args:`, args);
@ -994,7 +1000,7 @@ class SqliteClient extends KnexClient {
}
async functionDelete(args: any = {}) {
const _func = this.createDatabaseIfNotExists.name;
const _func = this.functionDelete.name;
// const result = new Result();
log.api(`${_func}:args:`, args);

Loading…
Cancel
Save