|
def | __init__ (self, host, database, user, port=3306, password=None) |
|
def | createDb (self, database, options=['-vvv']) |
|
def | execStmt (self, stmt, stdout=sys.stdout, options=['-vvv']) |
|
def | execScript (self, script, options=['-vvv']) |
|
def | runQuery (self, query) |
|
def | isView (self, table) |
|
def | exists (self, table) |
|
def | getConn (self) |
|
Definition at line 35 of file mysqlExecutor.py.
◆ __init__()
def lsst.datarel.mysqlExecutor.MysqlExecutor.__init__ |
( |
|
self, |
|
|
|
host, |
|
|
|
database, |
|
|
|
user, |
|
|
|
port = 3306 , |
|
|
|
password = None |
|
) |
| |
Definition at line 37 of file mysqlExecutor.py.
37 def __init__(self, host, database, user, port=3306, password=None):
41 self.database = database
43 if self.host
is not None and self.port
is not None and \
44 DbAuth.available(self.host, str(self.port)):
45 self.user = DbAuth.username(self.host, str(self.port))
46 password = DbAuth.password(self.host, str(self.port))
47 elif not os.path.exists(os.path.join(os.environ[
'HOME'],
".my.cnf")):
48 password = getpass.getpass(
"%s's MySQL password: " % user)
49 self.password = password
50 self.mysqlCmd = [
'mysql']
52 self.mysqlCmd += [
'-h', self.host]
54 self.mysqlCmd += [
'-P', str(self.port)]
56 self.mysqlCmd += [
'-u', self.user]
57 if password
is not None:
58 self.mysqlCmd += [
'-p' + self.password]
def __init__(self, needLockOnRead=True, data=None, cond=None)
◆ createDb()
def lsst.datarel.mysqlExecutor.MysqlExecutor.createDb |
( |
|
self, |
|
|
|
database, |
|
|
|
options = ['-vvv'] |
|
) |
| |
Definition at line 60 of file mysqlExecutor.py.
60 def createDb(self, database, options=['-vvv']):
61 if not isinstance(database, basestring):
62 raise TypeError(
'database name is not a string')
63 cmd = list(self.mysqlCmd)
65 cmd += [
'-e',
'CREATE DATABASE %s;' % database]
66 subprocess.check_call(cmd, stdout=sys.stdout, stderr=sys.stderr)
◆ execScript()
def lsst.datarel.mysqlExecutor.MysqlExecutor.execScript |
( |
|
self, |
|
|
|
script, |
|
|
|
options = ['-vvv'] |
|
) |
| |
Definition at line 82 of file mysqlExecutor.py.
82 def execScript(self, script, options=['-vvv']):
83 if not isinstance(script, basestring):
84 raise TypeError(
'Script file name is not a string')
85 if not os.path.isfile(script):
87 'Script %s does not exist or is not a file' % script)
88 with open(script,
'rb')
as f:
89 cmd = list(self.mysqlCmd)
90 if self.database
is not None:
91 cmd += [
'-D', self.database]
93 subprocess.check_call(cmd, stdin=f,
94 stdout=sys.stdout, stderr=sys.stderr)
◆ execStmt()
def lsst.datarel.mysqlExecutor.MysqlExecutor.execStmt |
( |
|
self, |
|
|
|
stmt, |
|
|
|
stdout = sys.stdout , |
|
|
|
options = ['-vvv'] |
|
) |
| |
Definition at line 70 of file mysqlExecutor.py.
70 def execStmt(self, stmt, stdout=sys.stdout, options=['-vvv']):
71 if not isinstance(stmt, basestring):
72 raise TypeError(
'SQL statement is not a string')
73 cmd = list(self.mysqlCmd)
74 if self.database
is not None:
75 cmd += [
'-D', self.database]
78 subprocess.check_call(cmd, stdout=stdout, stderr=sys.stderr)
◆ exists()
def lsst.datarel.mysqlExecutor.MysqlExecutor.exists |
( |
|
self, |
|
|
|
table |
|
) |
| |
Definition at line 116 of file mysqlExecutor.py.
117 with closing(self.getConn())
as conn:
118 with closing(conn.cursor())
as cursor:
119 cursor.execute(
'SELECT COUNT(*) FROM information_schema.tables ' 120 'WHERE table_schema=%s AND table_name=%s',
121 (self.database, table))
122 return cursor.fetchone()[0] == 1
◆ getConn()
def lsst.datarel.mysqlExecutor.MysqlExecutor.getConn |
( |
|
self | ) |
|
Definition at line 124 of file mysqlExecutor.py.
126 if self.host
is not None:
127 kw[
'host'] = self.host
128 if self.port
is not None:
129 kw[
'port'] = self.port
130 if self.user
is not None:
131 kw[
'user'] = self.user
132 if self.database
is not None:
133 kw[
'db'] = self.database
134 if self.password
is not None:
135 kw[
'passwd'] = self.password
136 return sql.connect(**kw)
◆ isView()
def lsst.datarel.mysqlExecutor.MysqlExecutor.isView |
( |
|
self, |
|
|
|
table |
|
) |
| |
Definition at line 108 of file mysqlExecutor.py.
108 def isView(self, table):
109 with closing(self.getConn())
as conn:
110 with closing(conn.cursor())
as cursor:
111 cursor.execute(
'SELECT COUNT(*) FROM information_schema.tables ' 112 'WHERE table_schema=%s AND table_name=%s AND ' 113 'table_type=\'VIEW\'', (self.database, table))
114 return cursor.fetchone()[0] == 1
◆ runQuery()
def lsst.datarel.mysqlExecutor.MysqlExecutor.runQuery |
( |
|
self, |
|
|
|
query |
|
) |
| |
Definition at line 98 of file mysqlExecutor.py.
98 def runQuery(self, query):
99 if not isinstance(query, basestring):
100 raise TypeError(
'Query is not a string')
101 with closing(self.getConn())
as conn:
102 with closing(conn.cursor())
as cursor:
105 cursor.execute(query)
106 return cursor.fetchall()
◆ database
lsst.datarel.mysqlExecutor.MysqlExecutor.database |
◆ host
lsst.datarel.mysqlExecutor.MysqlExecutor.host |
◆ mysqlCmd
lsst.datarel.mysqlExecutor.MysqlExecutor.mysqlCmd |
◆ password
lsst.datarel.mysqlExecutor.MysqlExecutor.password |
◆ port
lsst.datarel.mysqlExecutor.MysqlExecutor.port |
◆ user
lsst.datarel.mysqlExecutor.MysqlExecutor.user |
The documentation for this class was generated from the following file:
- /home/jenkins-slave/snowflake/release/lsstsw/stack/Linux64/datarel/14.0+77/python/lsst/datarel/mysqlExecutor.py