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
gaoqiong
MIGraphX
Commits
125e6ea2
"profiler/vscode:/vscode.git/clone" did not exist on "1f543bfa79de0687f9b6144b5dea10f4190c8892"
Commit
125e6ea2
authored
Jun 20, 2022
by
Paul
Browse files
Format
parent
9b176db8
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
12 deletions
+15
-12
src/include/migraphx/sqlite.hpp
src/include/migraphx/sqlite.hpp
+2
-1
src/sqlite.cpp
src/sqlite.cpp
+12
-9
test/sqlite.cpp
test/sqlite.cpp
+1
-2
No files found.
src/include/migraphx/sqlite.hpp
View file @
125e6ea2
...
@@ -18,7 +18,8 @@ struct sqlite
...
@@ -18,7 +18,8 @@ struct sqlite
static
sqlite
read
(
const
fs
::
path
&
p
);
static
sqlite
read
(
const
fs
::
path
&
p
);
static
sqlite
write
(
const
fs
::
path
&
p
);
static
sqlite
write
(
const
fs
::
path
&
p
);
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
std
::
string
>>
execute
(
const
std
::
string
&
s
);
std
::
vector
<
std
::
unordered_map
<
std
::
string
,
std
::
string
>>
execute
(
const
std
::
string
&
s
);
private:
private:
std
::
shared_ptr
<
sqlite_impl
>
impl
;
std
::
shared_ptr
<
sqlite_impl
>
impl
;
};
};
...
...
src/sqlite.cpp
View file @
125e6ea2
...
@@ -15,14 +15,14 @@ struct sqlite_impl
...
@@ -15,14 +15,14 @@ struct sqlite_impl
void
open
(
const
fs
::
path
&
p
,
int
flags
)
void
open
(
const
fs
::
path
&
p
,
int
flags
)
{
{
sqlite3
*
ptr_tmp
=
nullptr
;
sqlite3
*
ptr_tmp
=
nullptr
;
int
rc
=
sqlite3_open_v2
(
p
.
string
().
c_str
(),
&
ptr_tmp
,
flags
,
nullptr
);
int
rc
=
sqlite3_open_v2
(
p
.
string
().
c_str
(),
&
ptr_tmp
,
flags
,
nullptr
);
ptr
=
sqlite3_ptr
{
ptr_tmp
};
ptr
=
sqlite3_ptr
{
ptr_tmp
};
if
(
rc
!=
0
)
if
(
rc
!=
0
)
MIGRAPHX_THROW
(
"error opening "
+
p
.
string
()
+
": "
+
error_message
());
MIGRAPHX_THROW
(
"error opening "
+
p
.
string
()
+
": "
+
error_message
());
}
}
template
<
class
F
>
template
<
class
F
>
void
exec
(
const
char
*
sql
,
F
f
)
void
exec
(
const
char
*
sql
,
F
f
)
{
{
auto
callback
=
[](
void
*
obj
,
auto
...
xs
)
->
int
{
auto
callback
=
[](
void
*
obj
,
auto
...
xs
)
->
int
{
try
try
...
@@ -37,7 +37,7 @@ struct sqlite_impl
...
@@ -37,7 +37,7 @@ struct sqlite_impl
}
}
};
};
int
rc
=
sqlite3_exec
(
get
(),
sql
,
callback
,
&
f
,
nullptr
);
int
rc
=
sqlite3_exec
(
get
(),
sql
,
callback
,
&
f
,
nullptr
);
if
(
rc
!=
0
)
if
(
rc
!=
0
)
MIGRAPHX_THROW
(
error_message
());
MIGRAPHX_THROW
(
error_message
());
}
}
...
@@ -71,9 +71,12 @@ std::vector<std::unordered_map<std::string, std::string>> sqlite::execute(const
...
@@ -71,9 +71,12 @@ std::vector<std::unordered_map<std::string, std::string>> sqlite::execute(const
impl
->
exec
(
s
.
c_str
(),
[
&
](
int
n
,
char
**
texts
,
char
**
names
)
{
impl
->
exec
(
s
.
c_str
(),
[
&
](
int
n
,
char
**
texts
,
char
**
names
)
{
std
::
unordered_map
<
std
::
string
,
std
::
string
>
row
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
row
;
row
.
reserve
(
n
);
row
.
reserve
(
n
);
std
::
transform
(
names
,
names
+
n
,
texts
,
std
::
inserter
(
row
,
row
.
begin
()),
[
&
](
const
char
*
name
,
const
char
*
text
)
{
std
::
transform
(
return
std
::
make_pair
(
name
,
text
);
names
,
});
names
+
n
,
texts
,
std
::
inserter
(
row
,
row
.
begin
()),
[
&
](
const
char
*
name
,
const
char
*
text
)
{
return
std
::
make_pair
(
name
,
text
);
});
result
.
push_back
(
row
);
result
.
push_back
(
row
);
});
});
return
result
;
return
result
;
...
...
test/sqlite.cpp
View file @
125e6ea2
...
@@ -14,7 +14,6 @@ const std::string select_all = R"__migraphx__(
...
@@ -14,7 +14,6 @@ const std::string select_all = R"__migraphx__(
SELECT * FROM test_db;
SELECT * FROM test_db;
)__migraphx__"
;
)__migraphx__"
;
TEST_CASE
(
read_write
)
TEST_CASE
(
read_write
)
{
{
migraphx
::
tmp_dir
td
{};
migraphx
::
tmp_dir
td
{};
...
@@ -24,7 +23,7 @@ TEST_CASE(read_write)
...
@@ -24,7 +23,7 @@ TEST_CASE(read_write)
db
.
execute
(
create_table
);
db
.
execute
(
create_table
);
}
}
{
{
auto
db
=
migraphx
::
sqlite
::
read
(
db_path
);
auto
db
=
migraphx
::
sqlite
::
read
(
db_path
);
auto
rows
=
db
.
execute
(
select_all
);
auto
rows
=
db
.
execute
(
select_all
);
EXPECT
(
rows
.
size
()
==
1
);
EXPECT
(
rows
.
size
()
==
1
);
auto
row
=
rows
.
front
();
auto
row
=
rows
.
front
();
...
...
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