Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
U
uniset2
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
UniSet project repositories
uniset2
Commits
11c8f221
Commit
11c8f221
authored
Dec 26, 2012
by
Pavel Vainerman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
(SQLite): немного подправил интерфейс..
parent
272e10ba
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
19 additions
and
27 deletions
+19
-27
SQLiteInterface.cc
extensions/DBServer-SQLite/SQLiteInterface.cc
+15
-27
create_db.sh
extensions/DBServer-SQLite/create_db.sh
+4
-0
No files found.
extensions/DBServer-SQLite/SQLiteInterface.cc
View file @
11c8f221
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
/*! \file
/*! \file
* \author Pavel Vainerman
* \author Pavel Vainerman
*/
*/
// --------------------------------------------------------------------------
// --------------------------------------------------------------------------
#include <sstream>
#include <sstream>
#include <cstdio>
#include <cstdio>
#include "UniSetTypes.h"
#include "UniSetTypes.h"
...
@@ -38,22 +38,18 @@ queryok(false),
...
@@ -38,22 +38,18 @@ queryok(false),
connected
(
false
),
connected
(
false
),
opTimeout
(
300
),
opTimeout
(
300
),
opCheckPause
(
50
)
opCheckPause
(
50
)
{
{
}
}
SQLiteInterface
::~
SQLiteInterface
()
SQLiteInterface
::~
SQLiteInterface
()
{
{
close
();
close
();
delete
db
;
if
(
db
)
delete
db
;
}
}
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
bool
SQLiteInterface
::
ping
()
bool
SQLiteInterface
::
connect
(
const
string
dbfile
,
bool
create
)
{
return
db
&&
(
sqlite3_db_status
(
db
,
0
,
NULL
,
NULL
,
0
)
==
SQLITE_OK
);
}
// -----------------------------------------------------------------------------------------
bool
SQLiteInterface
::
connect
(
const
string
&
dbfile
,
bool
create
)
{
{
// т.к. sqlite3 по умолчанию, создаёт файл при открытии, то проверим "сами"
// т.к. sqlite3 по умолчанию, создаёт файл при открытии, то проверим "сами"
// if( !create && !UniSetTypes::file_exist(dbfile) )
// if( !create && !UniSetTypes::file_exist(dbfile) )
...
@@ -72,8 +68,7 @@ bool SQLiteInterface::connect( const string& dbfile, bool create )
...
@@ -72,8 +68,7 @@ bool SQLiteInterface::connect( const string& dbfile, bool create )
connected
=
false
;
connected
=
false
;
return
false
;
return
false
;
}
}
setOperationTimeout
(
opTimeout
);
connected
=
true
;
connected
=
true
;
return
true
;
return
true
;
}
}
...
@@ -85,18 +80,11 @@ bool SQLiteInterface::close()
...
@@ -85,18 +80,11 @@ bool SQLiteInterface::close()
sqlite3_close
(
db
);
sqlite3_close
(
db
);
db
=
0
;
db
=
0
;
}
}
return
true
;
return
true
;
}
}
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
void
SQLiteInterface
::
setOperationTimeout
(
timeout_t
msec
)
bool
SQLiteInterface
::
insert
(
const
string
q
)
{
opTimeout
=
msec
;
if
(
db
)
sqlite3_busy_timeout
(
db
,
opTimeout
);
}
// -----------------------------------------------------------------------------------------
bool
SQLiteInterface
::
insert
(
const
string
&
q
)
{
{
if
(
!
db
)
if
(
!
db
)
return
false
;
return
false
;
...
@@ -112,9 +100,9 @@ bool SQLiteInterface::insert( const string& q )
...
@@ -112,9 +100,9 @@ bool SQLiteInterface::insert( const string& q )
}
}
int
rc
=
sqlite3_step
(
pStmt
);
int
rc
=
sqlite3_step
(
pStmt
);
if
(
!
checkResult
(
rc
)
&&
!
wait
(
pStmt
,
SQLITE_DONE
)
)
if
(
!
checkResult
(
rc
)
&&
!
wait
(
pStmt
,
SQLITE_DONE
)
)
{
{
sqlite3_finalize
(
pStmt
);
sqlite3_finalize
(
pStmt
);
queryok
=
false
;
queryok
=
false
;
return
false
;
return
false
;
...
@@ -133,7 +121,7 @@ bool SQLiteInterface::checkResult( int rc )
...
@@ -133,7 +121,7 @@ bool SQLiteInterface::checkResult( int rc )
return
true
;
return
true
;
}
}
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
SQLiteResult
SQLiteInterface
::
query
(
const
string
&
q
)
SQLiteResult
SQLiteInterface
::
query
(
const
string
q
)
{
{
if
(
!
db
)
if
(
!
db
)
return
SQLiteResult
();
return
SQLiteResult
();
...
@@ -150,7 +138,7 @@ SQLiteResult SQLiteInterface::query( const string& q )
...
@@ -150,7 +138,7 @@ SQLiteResult SQLiteInterface::query( const string& q )
queryok
=
false
;
queryok
=
false
;
return
SQLiteResult
();
return
SQLiteResult
();
}
}
lastQ
=
q
;
lastQ
=
q
;
queryok
=
true
;
queryok
=
true
;
return
SQLiteResult
(
pStmt
,
true
);
return
SQLiteResult
(
pStmt
,
true
);
...
@@ -237,8 +225,8 @@ std::string as_string( SQLiteResult::COL::iterator& it )
...
@@ -237,8 +225,8 @@ std::string as_string( SQLiteResult::COL::iterator& it )
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
#if 0
#if 0
SQLiteResult::COL get_col( SQLiteResult::ROW::iterator& it )
SQLiteResult::COL get_col( SQLiteResult::ROW::iterator& it )
{
{
return (*it);
return (*it);
}
}
#endif
#endif
// -----------------------------------------------------------------------------------------
// -----------------------------------------------------------------------------------------
...
...
extensions/DBServer-SQLite/create_db.sh
View file @
11c8f221
...
@@ -21,6 +21,10 @@ INSERT INTO main_history VALUES(NULL,0,0,0,100,20.3,1,0);
...
@@ -21,6 +21,10 @@ INSERT INTO main_history VALUES(NULL,0,0,0,100,20.3,1,0);
INSERT INTO main_history VALUES
(
NULL,0,0,0,101,20.65,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,101,20.65,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,102,20.7,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,102,20.7,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,103,20.1,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,103,20.1,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,105,20.3,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,106,20.65,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,107,20233.7,1,0
)
;
INSERT INTO main_history VALUES
(
NULL,0,0,0,108,245560.67671,1,0
)
;
_EOF_
_EOF_
...
...
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