|
@@ -6,6 +6,10 @@ import (
|
|
|
"fmt"
|
|
"fmt"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
|
|
+var (
|
|
|
|
|
+ DBUtil *DBUtils
|
|
|
|
|
+)
|
|
|
|
|
+
|
|
|
type DBUtils struct {
|
|
type DBUtils struct {
|
|
|
User string
|
|
User string
|
|
|
Password string
|
|
Password string
|
|
@@ -58,14 +62,15 @@ func (dbUtil DBUtils) GetString(what string, from string, where string, whereval
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// GetRow(what, from, where, wherevalue)
|
|
// GetRow(what, from, where, wherevalue)
|
|
|
-func (dbUtil DBUtils) GetRow(options ...string) []string {
|
|
|
|
|
|
|
+func (dbUtil DBUtils) GetRow(options ...string) ([]string, error) {
|
|
|
var err error
|
|
var err error
|
|
|
|
|
+ var rows *sql.Rows // TODO fix this weird bug
|
|
|
|
|
|
|
|
- //if len(options) > 3 { // with or without where
|
|
|
|
|
- //rows, err := dbUtil.Handle.Query("SELECT " + options[0] + " FROM " + options[1] + " WHERE " + options[2] + " = " + options[3]) // TODO Parse?
|
|
|
|
|
- //} else {
|
|
|
|
|
- rows, err := dbUtil.Handle.Query("SELECT " + options[0] + " FROM " + options[1]) // TODO Parse?
|
|
|
|
|
- //}
|
|
|
|
|
|
|
+ if len(options) > 3 { // with or without where
|
|
|
|
|
+ rows, err = dbUtil.Handle.Query("SELECT " + options[0] + " FROM " + options[1] + " WHERE " + options[2] + " = \"" + options[3] + "\"") // TODO Parse?
|
|
|
|
|
+ } else {
|
|
|
|
|
+ rows, err = dbUtil.Handle.Query("SELECT " + options[0] + " FROM " + options[1]) // TODO Parse?
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
fmt.Println(err)
|
|
fmt.Println(err)
|
|
@@ -76,7 +81,7 @@ func (dbUtil DBUtils) GetRow(options ...string) []string {
|
|
|
fmt.Println("Failed to get columns", err)
|
|
fmt.Println("Failed to get columns", err)
|
|
|
var x []string;
|
|
var x []string;
|
|
|
x[0] = "";
|
|
x[0] = "";
|
|
|
- return x
|
|
|
|
|
|
|
+ return x, err
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Result is your slice string.
|
|
// Result is your slice string.
|
|
@@ -106,23 +111,6 @@ func (dbUtil DBUtils) GetRow(options ...string) []string {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-/*
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
- }
|
|
|
|
|
- defer rows.Close()
|
|
|
|
|
- for rows.Next() {
|
|
|
|
|
- err := rows.Scan(&username)
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
- }
|
|
|
|
|
- fmt.Println(username)
|
|
|
|
|
- }
|
|
|
|
|
- err = rows.Err()
|
|
|
|
|
- if err != nil {
|
|
|
|
|
- fmt.Println(err)
|
|
|
|
|
- }*/
|
|
|
|
|
-
|
|
|
|
|
return result
|
|
return result
|
|
|
|
|
|
|
|
}
|
|
}
|