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
94aa3f43
Commit
94aa3f43
authored
Feb 3, 2013
by
José Carlos Nieto
Browse files
Options
Downloads
Patches
Plain Diff
Alternative fetchAll function from MySQL.
parent
5adfedef
No related branches found
No related tags found
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
mysql/collection.go
+1
-1
1 addition, 1 deletion
mysql/collection.go
sqlite/_dumps/gotest.sqlite3.db
+0
-0
0 additions, 0 deletions
sqlite/_dumps/gotest.sqlite3.db
sqlite/collection.go
+32
-28
32 additions, 28 deletions
sqlite/collection.go
sqlite/sqlite.go
+2
-1
2 additions, 1 deletion
sqlite/sqlite.go
with
35 additions
and
30 deletions
mysql/collection.go
+
1
−
1
View file @
94aa3f43
/*
/*
Copyright (c) 2012 José Carlos Nieto, http://xiam.menteslibres.org/
Copyright (c) 2012
-2013
José Carlos Nieto, http://xiam.menteslibres.org/
Permission is hereby granted, free of charge, to any person obtaining
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
a copy of this software and associated documentation files (the
...
...
This diff is collapsed.
Click to expand it.
sqlite/_dumps/gotest.sqlite3.db
+
0
−
0
View file @
94aa3f43
No preview for this file type
This diff is collapsed.
Click to expand it.
sqlite/collection.go
+
32
−
28
View file @
94aa3f43
...
@@ -29,7 +29,6 @@ import (
...
@@ -29,7 +29,6 @@ import (
"github.com/gosexy/db"
"github.com/gosexy/db"
"github.com/gosexy/sugar"
"github.com/gosexy/sugar"
"github.com/gosexy/to"
"github.com/gosexy/to"
//_ "github.com/xiam/gosqlite3"
"reflect"
"reflect"
"regexp"
"regexp"
"strconv"
"strconv"
...
@@ -41,7 +40,8 @@ func (self *Table) Name() string {
...
@@ -41,7 +40,8 @@ func (self *Table) Name() string {
return
self
.
name
return
self
.
name
}
}
func
(
t
*
Table
)
slFetchAll
(
rows
sql
.
Rows
)
[]
db
.
Item
{
// Returns all items from a query.
func
(
self
*
Table
)
slFetchAll
(
rows
sql
.
Rows
)
[]
db
.
Item
{
items
:=
[]
db
.
Item
{}
items
:=
[]
db
.
Item
{}
...
@@ -51,42 +51,46 @@ func (t *Table) slFetchAll(rows sql.Rows) []db.Item {
...
@@ -51,42 +51,46 @@ func (t *Table) slFetchAll(rows sql.Rows) []db.Item {
columns
[
i
]
=
strings
.
ToLower
(
columns
[
i
])
columns
[
i
]
=
strings
.
ToLower
(
columns
[
i
])
}
}
res
:=
map
[
string
]
*
sql
.
RawBytes
{}
expecting
:=
len
(
columns
)
fargs
:=
[]
reflect
.
Value
{}
values
:=
make
([]
*
sql
.
RawBytes
,
expecting
)
scanArgs
:=
make
([]
interface
{},
expecting
)
for
_
,
name
:=
range
columns
{
for
i
:=
range
columns
{
res
[
name
]
=
&
sql
.
RawBytes
{}
scanArgs
[
i
]
=
&
values
[
i
]
fargs
=
append
(
fargs
,
reflect
.
ValueOf
(
res
[
name
]))
}
}
sn
:=
reflect
.
ValueOf
(
&
rows
)
fn
:=
sn
.
MethodByName
(
"Scan"
)
for
rows
.
Next
()
{
for
rows
.
Next
()
{
item
:=
db
.
Item
{}
item
:=
db
.
Item
{}
ret
:=
fn
.
Call
(
fargs
)
err
:=
rows
.
Scan
(
scanArgs
...
)
if
ret
[
0
]
.
IsNil
()
!=
true
{
if
err
!=
nil
{
panic
(
ret
[
0
]
.
Elem
()
.
Interface
()
.
(
error
)
)
panic
(
err
)
}
}
for
_
,
name
:=
range
columns
{
// Pending cleaner reflection magic.
strval
:=
fmt
.
Sprintf
(
"%s"
,
*
res
[
name
])
for
i
,
value
:=
range
values
{
column
:=
columns
[
i
]
switch
t
.
types
[
name
]
{
if
value
==
nil
{
item
[
column
]
=
nil
}
else
{
strval
:=
fmt
.
Sprintf
(
"%s"
,
*
value
)
switch
self
.
types
[
column
]
{
case
reflect
.
Uint64
:
case
reflect
.
Uint64
:
intval
,
_
:=
strconv
.
Atoi
(
strval
)
intval
,
_
:=
strconv
.
Atoi
(
strval
)
item
[
name
]
=
uint64
(
intval
)
item
[
column
]
=
uint64
(
intval
)
case
reflect
.
Int64
:
case
reflect
.
Int64
:
intval
,
_
:=
strconv
.
Atoi
(
strval
)
intval
,
_
:=
strconv
.
Atoi
(
strval
)
item
[
name
]
=
intval
item
[
column
]
=
intval
case
reflect
.
Float64
:
case
reflect
.
Float64
:
floatval
,
_
:=
strconv
.
ParseFloat
(
strval
,
10
)
floatval
,
_
:=
strconv
.
ParseFloat
(
strval
,
10
)
item
[
name
]
=
floatval
item
[
column
]
=
floatval
default
:
default
:
item
[
name
]
=
strval
item
[
column
]
=
strval
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
sqlite/sqlite.go
+
2
−
1
View file @
94aa3f43
/*
/*
Copyright (c) 2012 José Carlos Nieto, http://xiam.menteslibres.org/
Copyright (c) 2012
-2013
José Carlos Nieto, http://xiam.menteslibres.org/
Permission is hereby granted, free of charge, to any person obtaining
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
a copy of this software and associated documentation files (the
...
@@ -28,6 +28,7 @@ import (
...
@@ -28,6 +28,7 @@ import (
"fmt"
"fmt"
"github.com/gosexy/db"
"github.com/gosexy/db"
_
"github.com/xiam/gosqlite3"
_
"github.com/xiam/gosqlite3"
//_ "github.com/mattn/go-sqlite3"
//_ "bitbucket.org/minux/go.sqlite3"
//_ "bitbucket.org/minux/go.sqlite3"
"reflect"
"reflect"
"regexp"
"regexp"
...
...
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