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