@@ -26,7 +26,7 @@ func NewWithCleanupInterval(db *sql.DB, cleanupInterval time.Duration) *GodrorSt
26
26
27
27
func (g * GodrorStore ) Find (token string ) (b []byte , exists bool , err error ) {
28
28
fmt .Println ("Find" )
29
- stmt := ` SELECT data FROM sessions WHERE token = '` + token + ` ' AND current_timestamp < expiry`
29
+ stmt := fmt . Sprintf ( " SELECT data FROM sessions WHERE token = '%x ' AND current_timestamp < expiry" , token )
30
30
row := g .db .QueryRow (stmt )
31
31
err = row .Scan (& b )
32
32
if err == sql .ErrNoRows {
@@ -39,13 +39,13 @@ func (g *GodrorStore) Find(token string) (b []byte, exists bool, err error) {
39
39
40
40
func (g * GodrorStore ) Commit (token string , b []byte , expiry time.Time ) error {
41
41
fmt .Println ("Commit" )
42
- stmt := ` SELECT data FROM sessions WHERE token = '` + token + `'`
42
+ stmt := fmt . Sprintf ( " SELECT data FROM sessions WHERE token = '%x'" , token )
43
43
row := g .db .QueryRow (stmt )
44
44
err := row .Err ()
45
45
if row .Scan () == sql .ErrNoRows {
46
46
fmt .Println ("No Row Found" )
47
- stmt = `INSERT INTO sessions (token, data, expiry) VALUES ('` + token + ` ', '%x', to_timestamp('` + string (expiry .Format ("2006-01-02 15:04:05.00" )) + `', 'YYYY-MM-DD HH24:MI:SS.FF'))`
48
- stmt = fmt .Sprintf (stmt , b )
47
+ stmt = `INSERT INTO sessions (token, data, expiry) VALUES ('%x ', '%x', to_timestamp('` + string (expiry .Format ("2006-01-02 15:04:05.00" )) + `', 'YYYY-MM-DD HH24:MI:SS.FF'))`
48
+ stmt = fmt .Sprintf (stmt , token , b )
49
49
fmt .Println (stmt )
50
50
_ , err := g .db .Exec (stmt )
51
51
if err != nil {
@@ -58,8 +58,8 @@ func (g *GodrorStore) Commit(token string, b []byte, expiry time.Time) error {
58
58
}
59
59
60
60
fmt .Println ("Update session data" )
61
- stmt = `UPDATE sessions SET data = '%x', expiry = to_timestamp('` + string (expiry .Format ("2006-01-02 15:04:05.00" )) + `', 'YYYY-MM-DD HH24:MI:SS.FF') WHERE token = '` + token + ` '`
62
- stmt = fmt .Sprintf (stmt , b )
61
+ stmt = `UPDATE sessions SET data = '%x', expiry = to_timestamp('` + string (expiry .Format ("2006-01-02 15:04:05.00" )) + `', 'YYYY-MM-DD HH24:MI:SS.FF') WHERE token = '%x '`
62
+ stmt = fmt .Sprintf (stmt , b , token )
63
63
_ , err = g .db .Exec (stmt )
64
64
if err != nil {
65
65
return err
@@ -70,7 +70,7 @@ func (g *GodrorStore) Commit(token string, b []byte, expiry time.Time) error {
70
70
71
71
func (g * GodrorStore ) Delete (token string ) error {
72
72
fmt .Println ("Delete" )
73
- stmt := ` DELETE FROM session WHERE token = '` + token + `'`
73
+ stmt := fmt . Sprintf ( " DELETE FROM session WHERE token = '%x'" , token )
74
74
_ , err := g .db .Exec (stmt )
75
75
return err
76
76
}
0 commit comments