Skip to content
Toggle navigation
Projects
Groups
Snippets
Help
Project
/
import-sipkd-eis
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 582299fd
authored
Aug 25, 2017
by
aagusti
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
dbtools
1 parent
9f6797ee
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
62 additions
and
0 deletions
DbTools.py
DbTools.py
0 → 100644
View file @
582299f
from
string
import
ascii_lowercase
from
random
import
choice
import
informixdb
# http://stackoverflow.com/questions/2257441/random-string-generation-with-upper-case-letters-and-digits-in-python
CURSOR_NAME_COUNT
=
range
(
6
)
def
get_cursor_name
():
chars
=
string
.
ascii_lowercase
return
''
.
join
(
random
.
choice
(
chars
)
for
_
in
CURSOR_NAME_COUNT
)
class
OtherEngine
(
object
):
def
__init__
(
self
,
db_name
,
db_user
,
db_pass
):
self
.
db_name
=
db_name
self
.
db_user
=
db_user
self
.
db_pass
=
db_pass
self
.
conn
=
None
self
.
connected
=
False
def
get_connect
(
self
):
return
informixdb
.
connect
(
self
.
db_name
,
user
=
self
.
db_user
,
password
=
self
.
db_pass
)
def
connect
(
self
):
if
self
.
connected
:
return
self
.
conn
self
.
conn
=
self
.
get_connect
()
self
.
connected
=
True
return
self
.
conn
def
disconnect
(
self
):
if
self
.
connected
:
self
.
conn
.
close
()
self
.
connected
=
False
def
get_cursor
(
self
):
name
=
''
.
join
(
choice
(
ascii_lowercase
)
for
_
in
CURSOR_NAME_COUNT
)
return
self
.
conn
.
cursor
(
name
,
rowformat
=
informixdb
.
ROW_AS_DICT
)
#return self.conn.cursor(rowformat=informixdb.ROW_AS_OBJECT)
def
execute
(
self
,
sql
):
self
.
connect
()
cursor
=
self
.
get_cursor
()
cursor
.
execute
(
sql
)
cursor
.
close
()
def
fetchone
(
self
,
sql
):
self
.
connect
()
cursor
=
self
.
get_cursor
()
cursor
.
execute
(
sql
)
r
=
cursor
.
fetchone
()
cursor
.
close
()
return
r
def
fetchall
(
self
,
sql
):
self
.
connect
()
cursor
=
self
.
get_cursor
()
cursor
.
execute
(
sql
)
r
=
cursor
.
fetchall
()
cursor
.
close
()
return
r
Write
Preview
Markdown
is supported
Attach a file
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 post a comment