Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
GeoModel
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container 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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
GeoModelDev
GeoModel
Commits
7a261c8b
Commit
7a261c8b
authored
1 year ago
by
Riccardo Maria Bianchi
Committed by
Johannes Junggeburth
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Move SQLite return codes for column types to an Enum
parent
b79e1130
Branches
Branches containing commit
Tags
Tags containing commit
1 merge request
!327
New schema for the GeoModel SQLite database and updated I/O
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h
+59
-41
59 additions, 41 deletions
GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h
GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp
+20
-39
20 additions, 39 deletions
GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp
with
79 additions
and
80 deletions
GeoModelIO/GeoModelDBManager/GeoModelDBManager/GMDBManager.h
+
59
−
41
View file @
7a261c8b
...
@@ -358,68 +358,86 @@ class GMDBManager {
...
@@ -358,68 +358,86 @@ class GMDBManager {
private:
private:
/**
/* NOTE: 'sqlite3_column_type' return codes:
* @brief Create all the default DB tables.
- 1 INT
*/
- 2 FLOAT
bool
createTables
();
- 3 TEXT
- 4 BLOB
- 5 NULL
*/
enum
SQLiteColumnTypes
:
int
{
INT_TYPE
=
1
,
FLOAT_TYPE
=
2
,
TEXT_TYPE
=
3
,
BLOB_TYPE
=
4
,
NULL_TYPE
=
5
};
/**
/**
* @brief Create a custom DB table to store a list of published nodes.
* @brief Create all the default DB tables.
* @param tableName The table's name.
*/
* @param keyType The type of the 'key' that identifies the linked node.
bool
createTables
();
*/
bool
createTableCustomPublishedNodes
(
const
std
::
string
tableName
,
const
std
::
string
nodeType
,
const
std
::
type_info
*
keyType
);
void
addDBversion
(
std
::
string
version
);
/**
* @brief Create a custom DB table to store a list of published nodes.
* @param tableName The table's name.
* @param keyType The type of the 'key' that identifies the linked node.
*/
bool
createTableCustomPublishedNodes
(
const
std
::
string
tableName
,
const
std
::
string
nodeType
,
const
std
::
type_info
*
keyType
);
//
void
loadTestData(); // for debug only
void
addDBversion
(
std
::
string
version
);
std
::
string
getTableNameFromTableId
(
unsigned
int
tabId
);
// void loadTestData(); // for debug only
void
storeNodeType
(
std
::
string
nodeType
,
std
::
str
in
g
tab
leName
);
std
::
string
getTableNameFromTableId
(
unsigned
in
t
tab
Id
);
std
::
string
getTableNameFromN
odeType
(
const
std
::
string
&
nodeTyp
e
);
void
storeNodeType
(
std
::
string
n
odeType
,
std
::
string
tableNam
e
);
void
storeTableColumnNames
(
std
::
vector
<
std
::
string
>
input
);
std
::
string
getTableNameFromNodeType
(
const
std
::
string
&
nodeType
);
std
::
vector
<
std
::
string
>
getTableColumnNames
(
const
std
::
string
&
tableName
);
std
::
vector
<
std
::
string
>
getTableColumnNames
(
const
std
::
string
&
tableName
);
bool
hasTableBeenCreatedInDB
(
const
std
::
string_view
tableName
);
bool
hasTableBeenCreatedInDB
(
const
std
::
string_view
tableName
);
void
storeTableColumnNames
(
std
::
vector
<
std
::
string
>
input
);
int
getTableColIndex
(
const
std
::
string
&
tableName
,
bool
storeRootVolume
(
const
unsigned
&
id
,
const
std
::
string_view
nodeType
);
const
std
::
string
&
colName
);
int
getTableColIndex
(
const
std
::
string
&
tableName
,
const
std
::
string
&
colName
);
bool
storeRootVolume
(
const
unsigned
&
id
,
const
std
::
string
_view
nodeType
);
bool
storeRootVolume
(
const
unsigned
int
&
id
,
const
std
::
string
&
nodeType
);
std
::
string
m_dbpath
;
std
::
string
m_dbpath
;
bool
m_debug
;
bool
m_debug
;
// verbosity level
// verbosity level
int
m_verbose
;
int
m_verbose
;
/// stores the column names for each table
/// stores the column names for each table
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
m_tableNames
;
std
::
unordered_map
<
std
::
string
,
std
::
vector
<
std
::
string
>>
m_tableNames
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
m_childType_tableName
;
std
::
unordered_map
<
std
::
string
,
std
::
string
>
m_childType_tableName
;
/// cache for the list of tables in the DB
/// cache for the list of tables in the DB
// std::vector<std::string> m_cache_tables;
// std::vector<std::string> m_cache_tables;
std
::
set
<
std
::
string
>
m_cache_tables
;
std
::
set
<
std
::
string
>
m_cache_tables
;
std
::
unordered_map
<
unsigned
int
,
std
::
string
>
std
::
unordered_map
<
unsigned
int
,
std
::
string
>
m_cache_tableId_tableName
;
/// cache for tableID-->tableName
m_cache_tableId_tableName
;
/// cache for tableID-->tableName
std
::
unordered_map
<
unsigned
int
,
std
::
string
>
std
::
unordered_map
<
unsigned
int
,
std
::
string
>
m_cache_tableId_nodeType
;
/// cache for tableID-->nodeType
m_cache_tableId_nodeType
;
/// cache for tableID-->nodeType
std
::
unordered_map
<
std
::
string
,
std
::
string
>
std
::
unordered_map
<
std
::
string
,
std
::
string
>
m_cache_nodeType_tableName
;
/// cache for nodeType-->tableName
m_cache_nodeType_tableName
;
/// cache for nodeType-->tableName
std
::
unordered_map
<
std
::
string
,
unsigned
int
>
std
::
unordered_map
<
std
::
string
,
unsigned
int
>
m_cache_nodeType_tableID
;
/// cache for nodeType-->tableID
m_cache_nodeType_tableID
;
/// cache for nodeType-->tableID
protected
:
protected
:
class
Imp
;
class
Imp
;
Imp
*
m_d
;
Imp
*
m_d
;
};
};
#endif // GMDBManager_H
#endif // GMDBManager_H
This diff is collapsed.
Click to expand it.
GeoModelIO/GeoModelDBManager/src/GMDBManager.cpp
+
20
−
39
View file @
7a261c8b
...
@@ -328,13 +328,6 @@ DBRowsList GMDBManager::getTableRecords_VecVecData(
...
@@ -328,13 +328,6 @@ DBRowsList GMDBManager::getTableRecords_VecVecData(
for
(
int
i
=
0
;
i
<
ctotal
;
for
(
int
i
=
0
;
i
<
ctotal
;
i
++
)
i
++
)
{
{
/* NOTE: 'sqlite3_column_type' return codes:
- 1 INT
- 2 FLOAT
- 3 TEXT
- 4 BLOB
- 5 NULL
*/
int
datacode
=
sqlite3_column_type
(
stmt
,
i
);
int
datacode
=
sqlite3_column_type
(
stmt
,
i
);
// debug msg
// debug msg
// if (0==nRows) std::cout << "table: " << tableName << ", col " << i << "/" << ctotal << " -- typecode: " << datacode << std::endl;
// if (0==nRows) std::cout << "table: " << tableName << ", col " << i << "/" << ctotal << " -- typecode: " << datacode << std::endl;
...
@@ -344,21 +337,21 @@ DBRowsList GMDBManager::getTableRecords_VecVecData(
...
@@ -344,21 +337,21 @@ DBRowsList GMDBManager::getTableRecords_VecVecData(
std
::
string
valS
;
std
::
string
valS
;
// ** INT **
// ** INT **
if
(
1
==
datacode
)
if
(
SQLiteColumnTypes
::
INT_TYPE
==
datacode
)
{
{
valI
=
sqlite3_column_int
(
stmt
,
i
);
valI
=
sqlite3_column_int
(
stmt
,
i
);
// if (0==nRows) std::cout << "valI: " << valI << std::endl;// debug msg
// if (0==nRows) std::cout << "valI: " << valI << std::endl;// debug msg
nodeParams
.
push_back
(
valI
);
nodeParams
.
push_back
(
valI
);
}
}
// ** FLOAT **
// ** FLOAT **
else
if
(
2
==
datacode
)
else
if
(
SQLiteColumnTypes
::
FLOAT_TYPE
==
datacode
)
{
{
valD
=
sqlite3_column_double
(
stmt
,
i
);
valD
=
sqlite3_column_double
(
stmt
,
i
);
// if (0==nRows) std::cout << "valD: " << valD << std::endl;// debug msg
// if (0==nRows) std::cout << "valD: " << valD << std::endl;// debug msg
nodeParams
.
push_back
(
valD
);
nodeParams
.
push_back
(
valD
);
}
}
// ** TEXT **
// ** TEXT **
else
if
(
3
==
datacode
)
else
if
(
SQLiteColumnTypes
::
TEXT_TYPE
==
datacode
)
{
{
const
char
*
cc
=
(
char
*
)
sqlite3_column_text
(
stmt
,
i
);
const
char
*
cc
=
(
char
*
)
sqlite3_column_text
(
stmt
,
i
);
if
(
cc
==
NULL
)
if
(
cc
==
NULL
)
...
@@ -372,18 +365,18 @@ DBRowsList GMDBManager::getTableRecords_VecVecData(
...
@@ -372,18 +365,18 @@ DBRowsList GMDBManager::getTableRecords_VecVecData(
nodeParams
.
push_back
(
valS
);
nodeParams
.
push_back
(
valS
);
}
}
// ** BLOB **
// ** BLOB **
else
if
(
4
==
datacode
)
else
if
(
SQLiteColumnTypes
::
BLOB_TYPE
==
datacode
)
{
{
THROW_EXCEPTION
(
"ERROR!!! The 'BLOB' data format is not supported yet!!"
);
THROW_EXCEPTION
(
"ERROR!!! The 'BLOB' data format is not supported yet!!"
);
}
}
// ** NULL **
// ** NULL **
else
if
(
5
==
datacode
)
else
if
(
SQLiteColumnTypes
::
NULL_TYPE
==
datacode
)
{
{
THROW_EXCEPTION
(
"
WARNING
! 'NULL' format detected. Check that!"
);
THROW_EXCEPTION
(
"
ERROR!!
! 'NULL' format detected. Check that!"
);
}
}
else
else
{
{
THROW_EXCEPTION
(
"ERROR!!! You should NOT get here!! Unsupport SQLite data typecode: "
<<
datacode
<<
" -- Check this!!"
);
THROW_EXCEPTION
(
"ERROR!!! You should NOT get here!! Unsupport
ed
SQLite data typecode: "
<<
datacode
<<
" -- Check this!!"
);
}
}
}
}
records
.
push_back
(
nodeParams
);
records
.
push_back
(
nodeParams
);
...
@@ -431,7 +424,8 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
...
@@ -431,7 +424,8 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
{
{
// Count the Number of Columns in the Table
// Count the Number of Columns in the Table
int
ctotal
=
sqlite3_column_count
(
stmt
);
int
ctotal
=
sqlite3_column_count
(
stmt
);
// for this case, we should have only one column
// Note: for this case, we should have only one column of data;
// so, we throw an error if we get more than two columns in total
if
(
ctotal
>
2
)
if
(
ctotal
>
2
)
{
{
THROW_EXCEPTION
(
"ERROR! Table '"
<<
tableName
<<
"' is supposed to have two columns only, one for the ID and one for actual data; but it has '"
THROW_EXCEPTION
(
"ERROR! Table '"
<<
tableName
<<
"' is supposed to have two columns only, one for the ID and one for actual data; but it has '"
...
@@ -443,22 +437,11 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
...
@@ -443,22 +437,11 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
res
=
sqlite3_step
(
stmt
);
// Execute SQL Statement.
res
=
sqlite3_step
(
stmt
);
// Execute SQL Statement.
if
(
res
==
SQLITE_ROW
)
if
(
res
==
SQLITE_ROW
)
{
{
// stores the value contained in a single row
// NOTE:
// std::variant<int, long, float, double, std::string> rowValue;
// we are only interested in returning
// the 'data' column, that is column '1'
// we are only interested in returning the 'data' column, that is column '1'
// (while column '0' contains the ID)
// (column '0' contains the ID)
int
colData
=
1
;
int
colData
=
1
;
// for (int i = 0; i < ctotal;
// i++) // Loop times the number of columns in the table
// {
/* NOTE: 'sqlite3_column_type' return codes:
- 1 INT
- 2 FLOAT
- 3 TEXT
- 4 BLOB
- 5 NULL
*/
int
datacode
=
sqlite3_column_type
(
stmt
,
1
);
int
datacode
=
sqlite3_column_type
(
stmt
,
1
);
// debug msg
// debug msg
// std::cout << "table: " << tableName << ", col " << colData << "/" << ctotal << " -- typecode: " << datacode << std::endl;
// std::cout << "table: " << tableName << ", col " << colData << "/" << ctotal << " -- typecode: " << datacode << std::endl;
...
@@ -466,17 +449,17 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
...
@@ -466,17 +449,17 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
int
valI
{
0
};
int
valI
{
0
};
double
valD
{
0.
};
double
valD
{
0.
};
std
::
string
valS
;
std
::
string
valS
;
if
(
1
==
datacode
)
if
(
SQLiteColumnTypes
::
INT_TYPE
==
datacode
)
{
{
valI
=
sqlite3_column_int
(
stmt
,
colData
);
valI
=
sqlite3_column_int
(
stmt
,
colData
);
records
.
push_back
(
valI
);
records
.
push_back
(
valI
);
}
}
else
if
(
2
==
datacode
)
else
if
(
SQLiteColumnTypes
::
FLOAT_TYPE
==
datacode
)
{
{
valD
=
sqlite3_column_double
(
stmt
,
colData
);
valD
=
sqlite3_column_double
(
stmt
,
colData
);
records
.
push_back
(
valD
);
records
.
push_back
(
valD
);
}
}
else
if
(
3
==
datacode
)
else
if
(
SQLiteColumnTypes
::
TEXT_TYPE
==
datacode
)
{
{
const
char
*
cc
=
(
char
*
)
sqlite3_column_text
(
stmt
,
colData
);
const
char
*
cc
=
(
char
*
)
sqlite3_column_text
(
stmt
,
colData
);
if
(
cc
==
NULL
)
if
(
cc
==
NULL
)
...
@@ -489,20 +472,18 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
...
@@ -489,20 +472,18 @@ DBRowEntry GMDBManager::getTableRecords_VecData(
}
}
records
.
push_back
(
valS
);
records
.
push_back
(
valS
);
}
}
else
if
(
4
==
datacode
)
else
if
(
SQLiteColumnTypes
::
BLOB_TYPE
==
datacode
)
{
{
THROW_EXCEPTION
(
"ERROR!!! The 'BLOB' data format is not supported yet!!"
);
THROW_EXCEPTION
(
"ERROR!!! The 'BLOB' data format is not supported yet!!"
);
}
}
else
if
(
5
==
datacode
)
else
if
(
SQLiteColumnTypes
::
NULL_TYPE
==
datacode
)
{
{
std
::
cout
<<
"
WARNING
! 'NULL' format detected. Check that!"
<<
std
::
endl
;
std
::
cout
<<
"
ERROR!!
! 'NULL' format detected. Check that!"
<<
std
::
endl
;
}
}
else
else
{
{
THROW_EXCEPTION
(
"ERROR!!! You should NOT get here!! Unsupport SQLite data typecode: "
<<
datacode
<<
" -- Check this!!"
);
THROW_EXCEPTION
(
"ERROR!!! You should NOT get here!! Unsupport
ed
SQLite data typecode: "
<<
datacode
<<
" -- Check this!!"
);
}
}
// }
// records.push_back(rowValue);
}
}
if
(
res
==
SQLITE_DONE
||
res
==
SQLITE_ERROR
)
if
(
res
==
SQLITE_DONE
||
res
==
SQLITE_ERROR
)
...
...
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