Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dlib
Commits
7204ce1a
Commit
7204ce1a
authored
Jan 26, 2015
by
Davis King
Browse files
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
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
dlib/sqlite/sqlite.h
dlib/sqlite/sqlite.h
+52
-0
dlib/sqlite/sqlite_abstract.h
dlib/sqlite/sqlite_abstract.h
+50
-0
No files found.
dlib/sqlite/sqlite.h
View file @
7204ce1a
...
@@ -11,6 +11,7 @@
...
@@ -11,6 +11,7 @@
#include <sqlite3.h>
#include <sqlite3.h>
#include "../smart_pointers.h"
#include "../smart_pointers.h"
#include "../serialize.h"
#include "../serialize.h"
#include <limits>
// --------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------
...
@@ -223,6 +224,31 @@ namespace dlib
...
@@ -223,6 +224,31 @@ namespace dlib
return
sql_string
;
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
(
const
std
::
vector
<
char
>
get_column_as_blob
(
unsigned
long
idx
unsigned
long
idx
...
@@ -354,6 +380,32 @@ namespace dlib
...
@@ -354,6 +380,32 @@ namespace dlib
return
sqlite3_bind_parameter_index
(
stmt
,
name
.
c_str
());
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
(
void
bind_blob
(
unsigned
long
parameter_id
,
unsigned
long
parameter_id
,
const
std
::
vector
<
char
>&
item
const
std
::
vector
<
char
>&
item
...
...
dlib/sqlite/sqlite_abstract.h
View file @
7204ce1a
...
@@ -244,6 +244,31 @@ namespace dlib
...
@@ -244,6 +244,31 @@ namespace dlib
routines.
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
(
const
std
::
vector
<
char
>
get_column_as_blob
(
unsigned
long
idx
unsigned
long
idx
)
const
;
)
const
;
...
@@ -349,6 +374,31 @@ namespace dlib
...
@@ -349,6 +374,31 @@ namespace dlib
- returns 0
- 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
(
void
bind_blob
(
unsigned
long
parameter_id
,
unsigned
long
parameter_id
,
const
std
::
vector
<
char
>&
item
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