comparison SMART/Java/Python/mySql/MySqlTable.py @ 46:169d364ddd91

Uploaded
author m-zytnicki
date Mon, 30 Sep 2013 03:19:26 -0400
parents 44d5973c188c
children
comparison
equal deleted inserted replaced
45:e454402ba9d9 46:169d364ddd91
114 for values in lines: 114 for values in lines:
115 commands.append("INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join([MySqlTable.formatSql(values[variable], self.types[variable], self.sizes[variable]) for variable in self.variables]))) 115 commands.append("INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join([MySqlTable.formatSql(values[variable], self.types[variable], self.sizes[variable]) for variable in self.variables])))
116 self.mySqlConnection.executeManyQueries(commands) 116 self.mySqlConnection.executeManyQueries(commands)
117 117
118 118
119 def insertManyFormatted(self, lines):
120 """
121 Insert many lines
122 @param lines: the list of values
123 @type lines: list of lists
124 """
125 replacer = ["?"] * len(self.variables)
126 command = "INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join(replacer))
127 values = [[line[variable] for variable in self.variables] for line in lines]
128 self.mySqlConnection.executeManyFormattedQueries(command, values)
129
130
131 def rename(self, name): 119 def rename(self, name):
132 """ 120 """
133 Rename the table 121 Rename the table
134 @param name: the new name 122 @param name: the new name
135 @type name: string 123 @type name: string
227 Add a row to this table 215 Add a row to this table
228 @param values: the values of the row 216 @param values: the values of the row
229 @type values: dict 217 @type values: dict
230 @return: the id of the added row 218 @return: the id of the added row
231 """ 219 """
232 sqlValues = [values[variable] for variable in self.variables]
233 command = "INSERT INTO '%s' (%%s) VALUES (%s)" % (self.name, ", ".join(self.variables))
234 id = self.mySqlConnection.executeFormattedQueryQuery(command, sqlValues, True)
235 return id
236 sqlValues = [] 220 sqlValues = []
237 for variable in self.variables: 221 for variable in self.variables:
238 sqlValues.append(self.formatSql(values[variable], self.types[variable], self.sizes[variable])) 222 sqlValues.append(self.formatSql(values[variable], self.types[variable], self.sizes[variable]))
239 command = "INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join(sqlValues)) 223 command = "INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join(sqlValues))
240 id = self.mySqlConnection.executeQuery(command, True) 224 id = self.mySqlConnection.executeQuery(command, True)
345 Drop the content of the current table 329 Drop the content of the current table
346 """ 330 """
347 query = self.mySqlConnection.executeQuery("SELECT * FROM '%s'" % (self.name)) 331 query = self.mySqlConnection.executeQuery("SELECT * FROM '%s'" % (self.name))
348 print query.getLines() 332 print query.getLines()
349 333
334