Merge pull request #1804 from LazyDBA247-Anyvision/master

This commit is contained in:
Chris Lu 2021-02-14 09:00:39 -08:00 committed by GitHub
commit 4f4c52a6c7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 27 additions and 27 deletions

View file

@ -124,11 +124,11 @@ interpolateParams = false
[mysql2] # or memsql, tidb [mysql2] # or memsql, tidb
enabled = false enabled = false
createTable = """ createTable = """
CREATE TABLE IF NOT EXISTS %s ( CREATE TABLE IF NOT EXISTS ` + "`%s`" + ` (
dirhash BIGINT, dirhash BIGINT,
name VARCHAR(1000), name VARCHAR(1000),
directory TEXT, directory TEXT,
meta LONGBLOB, meta LONGBLOB,
PRIMARY KEY (dirhash, name) PRIMARY KEY (dirhash, name)
) DEFAULT CHARSET=utf8; ) DEFAULT CHARSET=utf8;
""" """
@ -164,7 +164,7 @@ connection_max_open = 100
[postgres2] [postgres2]
enabled = false enabled = false
createTable = """ createTable = """
CREATE TABLE IF NOT EXISTS %s ( CREATE TABLE IF NOT EXISTS "%s" (
dirhash BIGINT, dirhash BIGINT,
name VARCHAR(65535), name VARCHAR(65535),
directory VARCHAR(65535), directory VARCHAR(65535),

View file

@ -16,31 +16,31 @@ var (
) )
func (gen *SqlGenMysql) GetSqlInsert(bucket string) string { func (gen *SqlGenMysql) GetSqlInsert(bucket string) string {
return fmt.Sprintf("INSERT INTO %s (dirhash,name,directory,meta) VALUES(?,?,?,?)", bucket) return fmt.Sprintf("INSERT INTO `%s` (dirhash,name,directory,meta) VALUES(?,?,?,?)", bucket)
} }
func (gen *SqlGenMysql) GetSqlUpdate(bucket string) string { func (gen *SqlGenMysql) GetSqlUpdate(bucket string) string {
return fmt.Sprintf("UPDATE %s SET meta=? WHERE dirhash=? AND name=? AND directory=?", bucket) return fmt.Sprintf("UPDATE `%s` SET meta=? WHERE dirhash=? AND name=? AND directory=?", bucket)
} }
func (gen *SqlGenMysql) GetSqlFind(bucket string) string { func (gen *SqlGenMysql) GetSqlFind(bucket string) string {
return fmt.Sprintf("SELECT meta FROM %s WHERE dirhash=? AND name=? AND directory=?", bucket) return fmt.Sprintf("SELECT meta FROM `%s` WHERE dirhash=? AND name=? AND directory=?", bucket)
} }
func (gen *SqlGenMysql) GetSqlDelete(bucket string) string { func (gen *SqlGenMysql) GetSqlDelete(bucket string) string {
return fmt.Sprintf("DELETE FROM %s WHERE dirhash=? AND name=? AND directory=?", bucket) return fmt.Sprintf("DELETE FROM `%s` WHERE dirhash=? AND name=? AND directory=?", bucket)
} }
func (gen *SqlGenMysql) GetSqlDeleteFolderChildren(bucket string) string { func (gen *SqlGenMysql) GetSqlDeleteFolderChildren(bucket string) string {
return fmt.Sprintf("DELETE FROM %s WHERE dirhash=? AND directory=?", bucket) return fmt.Sprintf("DELETE FROM `%s` WHERE dirhash=? AND directory=?", bucket)
} }
func (gen *SqlGenMysql) GetSqlListExclusive(bucket string) string { func (gen *SqlGenMysql) GetSqlListExclusive(bucket string) string {
return fmt.Sprintf("SELECT NAME, meta FROM %s WHERE dirhash=? AND name>? AND directory=? AND name like ? ORDER BY NAME ASC LIMIT ?", bucket) return fmt.Sprintf("SELECT NAME, meta FROM `%s` WHERE dirhash=? AND name>? AND directory=? AND name like ? ORDER BY NAME ASC LIMIT ?", bucket)
} }
func (gen *SqlGenMysql) GetSqlListInclusive(bucket string) string { func (gen *SqlGenMysql) GetSqlListInclusive(bucket string) string {
return fmt.Sprintf("SELECT NAME, meta FROM %s WHERE dirhash=? AND name>=? AND directory=? AND name like ? ORDER BY NAME ASC LIMIT ?", bucket) return fmt.Sprintf("SELECT NAME, meta FROM `%s` WHERE dirhash=? AND name>=? AND directory=? AND name like ? ORDER BY NAME ASC LIMIT ?", bucket)
} }
func (gen *SqlGenMysql) GetSqlCreateTable(bucket string) string { func (gen *SqlGenMysql) GetSqlCreateTable(bucket string) string {

View file

@ -47,7 +47,7 @@ func (store *MysqlStore) initialize(user, password, hostname string, port int, d
store.SupportBucketTable = false store.SupportBucketTable = false
store.SqlGenerator = &SqlGenMysql{ store.SqlGenerator = &SqlGenMysql{
CreateTableSqlTemplate: "", CreateTableSqlTemplate: "",
DropTableSqlTemplate: "drop table %s", DropTableSqlTemplate: "drop table `%s`",
} }
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database) sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)

View file

@ -50,7 +50,7 @@ func (store *MysqlStore2) initialize(createTable, user, password, hostname strin
store.SupportBucketTable = true store.SupportBucketTable = true
store.SqlGenerator = &mysql.SqlGenMysql{ store.SqlGenerator = &mysql.SqlGenMysql{
CreateTableSqlTemplate: createTable, CreateTableSqlTemplate: createTable,
DropTableSqlTemplate: "drop table %s", DropTableSqlTemplate: "drop table `%s`",
} }
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database) sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, user, password, hostname, port, database)

View file

@ -1,10 +1,10 @@
package postgres package postgres
import ( import (
"fmt" `fmt`
"github.com/chrislusf/seaweedfs/weed/filer/abstract_sql" `github.com/chrislusf/seaweedfs/weed/filer/abstract_sql`
_ "github.com/lib/pq" _ `github.com/lib/pq`
) )
type SqlGenPostgres struct { type SqlGenPostgres struct {
@ -17,31 +17,31 @@ var (
) )
func (gen *SqlGenPostgres) GetSqlInsert(bucket string) string { func (gen *SqlGenPostgres) GetSqlInsert(bucket string) string {
return fmt.Sprintf("INSERT INTO %s (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)", bucket) return fmt.Sprintf(`INSERT INTO "%s" (dirhash,name,directory,meta) VALUES($1,$2,$3,$4)`, bucket)
} }
func (gen *SqlGenPostgres) GetSqlUpdate(bucket string) string { func (gen *SqlGenPostgres) GetSqlUpdate(bucket string) string {
return fmt.Sprintf("UPDATE %s SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4", bucket) return fmt.Sprintf(`UPDATE "%s" SET meta=$1 WHERE dirhash=$2 AND name=$3 AND directory=$4`, bucket)
} }
func (gen *SqlGenPostgres) GetSqlFind(bucket string) string { func (gen *SqlGenPostgres) GetSqlFind(bucket string) string {
return fmt.Sprintf("SELECT meta FROM %s WHERE dirhash=$1 AND name=$2 AND directory=$3", bucket) return fmt.Sprintf(`SELECT meta FROM "%s" WHERE dirhash=$1 AND name=$2 AND directory=$3`, bucket)
} }
func (gen *SqlGenPostgres) GetSqlDelete(bucket string) string { func (gen *SqlGenPostgres) GetSqlDelete(bucket string) string {
return fmt.Sprintf("DELETE FROM %s WHERE dirhash=$1 AND name=$2 AND directory=$3", bucket) return fmt.Sprintf(`DELETE FROM "%s" WHERE dirhash=$1 AND name=$2 AND directory=$3`, bucket)
} }
func (gen *SqlGenPostgres) GetSqlDeleteFolderChildren(bucket string) string { func (gen *SqlGenPostgres) GetSqlDeleteFolderChildren(bucket string) string {
return fmt.Sprintf("DELETE FROM %s WHERE dirhash=$1 AND directory=$2", bucket) return fmt.Sprintf(`DELETE FROM "%s" WHERE dirhash=$1 AND directory=$2`, bucket)
} }
func (gen *SqlGenPostgres) GetSqlListExclusive(bucket string) string { func (gen *SqlGenPostgres) GetSqlListExclusive(bucket string) string {
return fmt.Sprintf("SELECT NAME, meta FROM %s WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5", bucket) return fmt.Sprintf(`SELECT NAME, meta FROM "%s" WHERE dirhash=$1 AND name>$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5`, bucket)
} }
func (gen *SqlGenPostgres) GetSqlListInclusive(bucket string) string { func (gen *SqlGenPostgres) GetSqlListInclusive(bucket string) string {
return fmt.Sprintf("SELECT NAME, meta FROM %s WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5", bucket) return fmt.Sprintf(`SELECT NAME, meta FROM "%s" WHERE dirhash=$1 AND name>=$2 AND directory=$3 AND name like $4 ORDER BY NAME ASC LIMIT $5`, bucket)
} }
func (gen *SqlGenPostgres) GetSqlCreateTable(bucket string) string { func (gen *SqlGenPostgres) GetSqlCreateTable(bucket string) string {

View file

@ -45,7 +45,7 @@ func (store *PostgresStore) initialize(user, password, hostname string, port int
store.SupportBucketTable = false store.SupportBucketTable = false
store.SqlGenerator = &SqlGenPostgres{ store.SqlGenerator = &SqlGenPostgres{
CreateTableSqlTemplate: "", CreateTableSqlTemplate: "",
DropTableSqlTemplate: "drop table %s", DropTableSqlTemplate: `drop table "%s"`,
} }
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)

View file

@ -48,7 +48,7 @@ func (store *PostgresStore2) initialize(createTable, user, password, hostname st
store.SupportBucketTable = true store.SupportBucketTable = true
store.SqlGenerator = &postgres.SqlGenPostgres{ store.SqlGenerator = &postgres.SqlGenPostgres{
CreateTableSqlTemplate: createTable, CreateTableSqlTemplate: createTable,
DropTableSqlTemplate: "drop table %s", DropTableSqlTemplate: `drop table "%s"`,
} }
sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode) sqlUrl := fmt.Sprintf(CONNECTION_URL_PATTERN, hostname, port, sslmode)