good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
U
upper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
open
upper
Commits
06da7349
Commit
06da7349
authored
Jun 17, 2014
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Better debugger functionality.
parent
05f86ea8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
postgresql/database.go
+40
-19
40 additions, 19 deletions
postgresql/database.go
util/sqlutil/main.go
+26
-4
26 additions, 4 deletions
util/sqlutil/main.go
with
66 additions
and
23 deletions
postgresql/database.go
+
40
−
19
View file @
06da7349
...
@@ -70,6 +70,13 @@ func debugEnabled() bool {
...
@@ -70,6 +70,13 @@ func debugEnabled() bool {
return
false
return
false
}
}
func
debugLog
(
query
string
,
args
[]
interface
{},
err
error
)
{
if
debugEnabled
()
==
true
{
d
:=
sqlutil
.
Debug
{
query
,
args
,
err
}
d
.
Print
()
}
}
func
init
()
{
func
init
()
{
template
=
&
sqlgen
.
Template
{
template
=
&
sqlgen
.
Template
{
...
@@ -106,68 +113,82 @@ func init() {
...
@@ -106,68 +113,82 @@ func init() {
}
}
func
(
self
*
Source
)
doExec
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
sql
.
Result
,
error
)
{
func
(
self
*
Source
)
doExec
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
sql
.
Result
,
error
)
{
var
query
string
var
res
sql
.
Result
var
err
error
defer
func
()
{
debugLog
(
query
,
args
,
err
)
}()
if
self
.
session
==
nil
{
if
self
.
session
==
nil
{
return
nil
,
db
.
ErrNotConnected
return
nil
,
db
.
ErrNotConnected
}
}
query
:
=
stmt
.
Compile
(
template
)
query
=
stmt
.
Compile
(
template
)
l
:=
len
(
args
)
l
:=
len
(
args
)
for
i
:=
0
;
i
<
l
;
i
++
{
for
i
:=
0
;
i
<
l
;
i
++
{
query
=
strings
.
Replace
(
query
,
`?`
,
fmt
.
Sprintf
(
`$%d`
,
i
+
1
),
1
)
query
=
strings
.
Replace
(
query
,
`?`
,
fmt
.
Sprintf
(
`$%d`
,
i
+
1
),
1
)
}
}
if
debugEnabled
()
==
true
{
sqlutil
.
DebugQuery
(
query
,
args
)
}
if
self
.
tx
!=
nil
{
if
self
.
tx
!=
nil
{
return
self
.
tx
.
Exec
(
query
,
args
...
)
res
,
err
=
self
.
tx
.
Exec
(
query
,
args
...
)
}
else
{
res
,
err
=
self
.
session
.
Exec
(
query
,
args
...
)
}
}
return
self
.
session
.
Exec
(
query
,
args
...
)
return
res
,
err
}
}
func
(
self
*
Source
)
doQuery
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Rows
,
error
)
{
func
(
self
*
Source
)
doQuery
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Rows
,
error
)
{
var
rows
*
sql
.
Rows
var
query
string
var
err
error
defer
func
()
{
debugLog
(
query
,
args
,
err
)
}()
if
self
.
session
==
nil
{
if
self
.
session
==
nil
{
return
nil
,
db
.
ErrNotConnected
return
nil
,
db
.
ErrNotConnected
}
}
query
:
=
stmt
.
Compile
(
template
)
query
=
stmt
.
Compile
(
template
)
l
:=
len
(
args
)
l
:=
len
(
args
)
for
i
:=
0
;
i
<
l
;
i
++
{
for
i
:=
0
;
i
<
l
;
i
++
{
query
=
strings
.
Replace
(
query
,
`?`
,
fmt
.
Sprintf
(
`$%d`
,
i
+
1
),
1
)
query
=
strings
.
Replace
(
query
,
`?`
,
fmt
.
Sprintf
(
`$%d`
,
i
+
1
),
1
)
}
}
if
debugEnabled
()
==
true
{
sqlutil
.
DebugQuery
(
query
,
args
)
}
if
self
.
tx
!=
nil
{
if
self
.
tx
!=
nil
{
return
self
.
tx
.
Query
(
query
,
args
...
)
rows
,
err
=
self
.
tx
.
Query
(
query
,
args
...
)
}
else
{
rows
,
err
=
self
.
session
.
Query
(
query
,
args
...
)
}
}
return
self
.
session
.
Query
(
query
,
args
...
)
return
rows
,
err
}
}
func
(
self
*
Source
)
doQueryRow
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Row
,
error
)
{
func
(
self
*
Source
)
doQueryRow
(
stmt
sqlgen
.
Statement
,
args
...
interface
{})
(
*
sql
.
Row
,
error
)
{
var
query
string
var
err
error
defer
func
()
{
debugLog
(
query
,
args
,
err
)
}()
if
self
.
session
==
nil
{
if
self
.
session
==
nil
{
return
nil
,
db
.
ErrNotConnected
return
nil
,
db
.
ErrNotConnected
}
}
query
:
=
stmt
.
Compile
(
template
)
query
=
stmt
.
Compile
(
template
)
l
:=
len
(
args
)
l
:=
len
(
args
)
for
i
:=
0
;
i
<
l
;
i
++
{
for
i
:=
0
;
i
<
l
;
i
++
{
query
=
strings
.
Replace
(
query
,
`?`
,
fmt
.
Sprintf
(
`$%d`
,
i
+
1
),
1
)
query
=
strings
.
Replace
(
query
,
`?`
,
fmt
.
Sprintf
(
`$%d`
,
i
+
1
),
1
)
}
}
if
debugEnabled
()
==
true
{
sqlutil
.
DebugQuery
(
query
,
args
)
}
if
self
.
tx
!=
nil
{
if
self
.
tx
!=
nil
{
return
self
.
tx
.
QueryRow
(
query
,
args
...
),
nil
return
self
.
tx
.
QueryRow
(
query
,
args
...
),
nil
}
}
...
...
This diff is collapsed.
Click to expand it.
util/sqlutil/main.go
+
26
−
4
View file @
06da7349
...
@@ -25,6 +25,7 @@ package sqlutil
...
@@ -25,6 +25,7 @@ package sqlutil
import
(
import
(
"database/sql"
"database/sql"
"fmt"
"log"
"log"
"menteslibres.net/gosexy/to"
"menteslibres.net/gosexy/to"
"reflect"
"reflect"
...
@@ -43,10 +44,31 @@ type T struct {
...
@@ -43,10 +44,31 @@ type T struct {
ColumnTypes
map
[
string
]
reflect
.
Kind
ColumnTypes
map
[
string
]
reflect
.
Kind
}
}
func
DebugQuery
(
s
string
,
args
[]
interface
{})
{
type
Debug
struct
{
s
=
reInvisibleChars
.
ReplaceAllString
(
s
,
` `
)
SQL
string
s
=
strings
.
TrimSpace
(
s
)
Args
[]
interface
{}
log
.
Printf
(
"
\n\t
SQL: %s
\n\t
ARGS: %v
\n\n
"
,
s
,
args
)
Err
error
}
func
(
self
*
Debug
)
Print
()
{
self
.
SQL
=
reInvisibleChars
.
ReplaceAllString
(
self
.
SQL
,
` `
)
self
.
SQL
=
strings
.
TrimSpace
(
self
.
SQL
)
s
:=
make
([]
string
,
0
,
3
)
if
self
.
SQL
!=
""
{
s
=
append
(
s
,
fmt
.
Sprintf
(
`SQL: %s`
,
self
.
SQL
))
}
if
len
(
self
.
Args
)
>
0
{
s
=
append
(
s
,
fmt
.
Sprintf
(
`ARG: %s`
,
self
.
Args
))
}
if
self
.
Err
!=
nil
{
s
=
append
(
s
,
fmt
.
Sprintf
(
`ERR: %q`
,
self
.
Err
))
}
log
.
Printf
(
"
\n\t
%s
\n\n
"
,
strings
.
Join
(
s
,
"
\n\t
"
))
}
}
func
(
self
*
T
)
ColumnLike
(
s
string
)
string
{
func
(
self
*
T
)
ColumnLike
(
s
string
)
string
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment