Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
7204ce1a
Commit
7204ce1a
authored
Jan 27, 2015
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added templated versions of get_column() and bind() that inter what
type to get/bind based on the type of variable passed in.
parent
0c23aae4
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
sqlite.h
dlib/sqlite/sqlite.h
+52
-0
sqlite_abstract.h
dlib/sqlite/sqlite_abstract.h
+50
-0
No files found.
dlib/sqlite/sqlite.h
View file @
7204ce1a
...
...
@@ -11,6 +11,7 @@
#include <sqlite3.h>
#include "../smart_pointers.h"
#include "../serialize.h"
#include <limits>
// --------------------------------------------------------------------------------------------
...
...
@@ -223,6 +224,31 @@ namespace dlib
return
sql_string
;
}
template
<
typename
T
>
typename
enable_if_c
<
std
::
numeric_limits
<
T
>::
is_integer
>::
type
get_column
(
unsigned
long
idx
,
T
&
item
)
const
{
if
(
sizeof
(
T
)
<=
4
)
item
=
get_column_as_int
(
idx
);
else
item
=
get_column_as_int64
(
idx
);
}
void
get_column
(
unsigned
long
idx
,
std
::
string
&
item
)
const
{
item
=
get_column_as_text
(
idx
);
}
void
get_column
(
unsigned
long
idx
,
float
&
item
)
const
{
item
=
get_column_as_double
(
idx
);
}
void
get_column
(
unsigned
long
idx
,
double
&
item
)
const
{
item
=
get_column_as_double
(
idx
);
}
void
get_column
(
unsigned
long
idx
,
long
double
&
item
)
const
{
item
=
get_column_as_double
(
idx
);
}
template
<
typename
T
>
typename
disable_if_c
<
std
::
numeric_limits
<
T
>::
is_integer
>::
type
get_column
(
unsigned
long
idx
,
T
&
item
)
const
{
get_column_as_object
(
idx
,
item
);
}
const
std
::
vector
<
char
>
get_column_as_blob
(
unsigned
long
idx
...
...
@@ -354,6 +380,32 @@ namespace dlib
return
sqlite3_bind_parameter_index
(
stmt
,
name
.
c_str
());
}
template
<
typename
T
>
typename
enable_if_c
<
std
::
numeric_limits
<
T
>::
is_integer
>::
type
bind
(
unsigned
long
idx
,
T
&
item
)
{
if
(
sizeof
(
T
)
<=
4
)
bind_int
(
idx
,
item
);
else
bind_int64
(
idx
,
item
);
}
void
bind
(
unsigned
long
idx
,
std
::
string
&
item
)
{
bind_text
(
idx
,
item
);
}
void
bind
(
unsigned
long
idx
,
float
&
item
)
{
bind_double
(
idx
,
item
);
}
void
bind
(
unsigned
long
idx
,
double
&
item
)
{
bind_double
(
idx
,
item
);
}
void
bind
(
unsigned
long
idx
,
long
double
&
item
)
{
bind_double
(
idx
,
item
);
}
template
<
typename
T
>
typename
disable_if_c
<
std
::
numeric_limits
<
T
>::
is_integer
>::
type
bind
(
unsigned
long
idx
,
T
&
item
)
{
bind_object
(
idx
,
item
);
}
void
bind_blob
(
unsigned
long
parameter_id
,
const
std
::
vector
<
char
>&
item
...
...
dlib/sqlite/sqlite_abstract.h
View file @
7204ce1a
...
...
@@ -244,6 +244,31 @@ namespace dlib
routines.
!*/
template
<
typename
T
>
void
get_column
(
unsigned
long
idx
,
T
&
item
)
const
;
/*!
requires
- idx < get_num_columns()
ensures
- This function automatically selects how to extract the column data based
on the type of item given. In particular:
- if (T is a 32bit or smaller built in integer type) then
- #item == get_column_as_int(idx)
- else if (T is a 64bit built in integer type) then
- #item == get_column_as_int64(idx)
- else if (T is float, double, or long double) then
- #item == get_column_as_double(idx)
- else if (T is std::string) then
- #item == get_column_as_text(idx)
- else
- invokes: get_column_as_object(idx, item)
!*/
const
std
::
vector
<
char
>
get_column_as_blob
(
unsigned
long
idx
)
const
;
...
...
@@ -349,6 +374,31 @@ namespace dlib
- returns 0
!*/
template
<
typename
T
>
void
bind
(
unsigned
long
parameter_id
,
T
&
item
)
const
;
/*!
requires
- 1 <= parameter_id <= get_max_parameter_id()
ensures
- This function automatically selects how to bind item to a statement based
on the type of item given. In particular:
- if (T is a 32bit or smaller built in integer type) then
- invokes: bind_int(parameter_id, item)
- else if (T is a 64bit built in integer type) then
- invokes: bind_int64(parameter_id, item)
- else if (T is float, double, or long double) then
- invokes: bind_double(parameter_id, item)
- else if (T is std::string) then
- invokes: bind_text(parameter_id, item)
- else
- invokes: bind_object(parameter_id, item)
!*/
void
bind_blob
(
unsigned
long
parameter_id
,
const
std
::
vector
<
char
>&
item
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment