|
@ -29,25 +29,31 @@ type Query struct { |
|
|
stmt *sql.Stmt |
|
|
stmt *sql.Stmt |
|
|
conn *sql.DB |
|
|
conn *sql.DB |
|
|
debug bool |
|
|
debug bool |
|
|
|
|
|
dbtype string |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func NewQuery(t ...string) *Query { |
|
|
func NewQuery(t ...string) *Query { |
|
|
|
|
|
|
|
|
var conn_type *sql.DB = DB |
|
|
var conn_type *sql.DB = DB |
|
|
|
|
|
|
|
|
|
|
|
var db_type string = "mysql" |
|
|
|
|
|
|
|
|
if len(t) > 0 { |
|
|
if len(t) > 0 { |
|
|
switch t[0] { |
|
|
switch t[0] { |
|
|
case "mysql": |
|
|
case "mysql": |
|
|
conn_type = DB |
|
|
conn_type = DB |
|
|
|
|
|
db_type = "mysql" |
|
|
|
|
|
|
|
|
case "mssql": //sql server
|
|
|
case "mssql": //sql server
|
|
|
conn_type = MSDB_CONN |
|
|
conn_type = MSDB_CONN |
|
|
|
|
|
db_type = "mssql" |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return &Query{ |
|
|
return &Query{ |
|
|
conn: conn_type, |
|
|
|
|
|
|
|
|
conn: conn_type, |
|
|
|
|
|
dbtype: db_type, |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
@ -149,7 +155,7 @@ func (this *Query) QueryStmt() error { |
|
|
return errors.New("参数错误,没有数据表") |
|
|
return errors.New("参数错误,没有数据表") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
table := getTableName(this.dbname, this.table) |
|
|
|
|
|
|
|
|
table := getTableName(this.dbname, this.table, this.dbtype) |
|
|
|
|
|
|
|
|
// var err error
|
|
|
// var err error
|
|
|
|
|
|
|
|
@ -174,9 +180,9 @@ func (this *Query) QueryStmt() error { |
|
|
continue |
|
|
continue |
|
|
} |
|
|
} |
|
|
if len(joinitem) == 3 { |
|
|
if len(joinitem) == 3 { |
|
|
sql = helper.StringJoin(sql, " ", joinitem[2], " join ", getTableName(this.dbname, joinitem[0]), " on ", joinitem[1]) |
|
|
|
|
|
|
|
|
sql = helper.StringJoin(sql, " ", joinitem[2], " join ", getTableName(this.dbname, joinitem[0], this.dbtype), " on ", joinitem[1]) |
|
|
} else { //默认左连接
|
|
|
} else { //默认左连接
|
|
|
sql = helper.StringJoin(sql, " left join ", getTableName(this.dbname, joinitem[0]), " on ", joinitem[1]) |
|
|
|
|
|
|
|
|
sql = helper.StringJoin(sql, " left join ", getTableName(this.dbname, joinitem[0], this.dbtype), " on ", joinitem[1]) |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -250,7 +256,7 @@ func (this *Query) UpdateStmt() error { |
|
|
return errors.New("参数错误,缺少条件") |
|
|
return errors.New("参数错误,缺少条件") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dbName := getTableName(this.dbname, this.table) |
|
|
|
|
|
|
|
|
dbName := getTableName(this.dbname, this.table, this.dbtype) |
|
|
|
|
|
|
|
|
var sql string |
|
|
var sql string |
|
|
|
|
|
|
|
@ -294,7 +300,7 @@ func (this *Query) CreateStmt() error { |
|
|
return errors.New("参数错误,没有数据表") |
|
|
return errors.New("参数错误,没有数据表") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dbName := getTableName(this.dbname, this.table) |
|
|
|
|
|
|
|
|
dbName := getTableName(this.dbname, this.table, this.dbtype) |
|
|
|
|
|
|
|
|
var sql string |
|
|
var sql string |
|
|
|
|
|
|
|
@ -339,7 +345,7 @@ func (this *Query) DeleteStmt() error { |
|
|
return errors.New("参数错误,缺少条件") |
|
|
return errors.New("参数错误,缺少条件") |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
dbName := getTableName(this.dbname, this.table) |
|
|
|
|
|
|
|
|
dbName := getTableName(this.dbname, this.table, this.dbtype) |
|
|
|
|
|
|
|
|
var sql string |
|
|
var sql string |
|
|
|
|
|
|
|
|