Mercurial > repos > yufei-luo > s_mart
comparison SMART/Java/Python/mySql/MySqlTable.py @ 18:94ab73e8a190
Uploaded
author | m-zytnicki |
---|---|
date | Mon, 29 Apr 2013 03:20:15 -0400 |
parents | 769e306b7933 |
children |
comparison
equal
deleted
inserted
replaced
17:b0e8584489e6 | 18:94ab73e8a190 |
---|---|
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 | |
119 def rename(self, name): | 131 def rename(self, name): |
120 """ | 132 """ |
121 Rename the table | 133 Rename the table |
122 @param name: the new name | 134 @param name: the new name |
123 @type name: string | 135 @type name: string |
215 Add a row to this table | 227 Add a row to this table |
216 @param values: the values of the row | 228 @param values: the values of the row |
217 @type values: dict | 229 @type values: dict |
218 @return: the id of the added row | 230 @return: the id of the added row |
219 """ | 231 """ |
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 | |
220 sqlValues = [] | 236 sqlValues = [] |
221 for variable in self.variables: | 237 for variable in self.variables: |
222 sqlValues.append(self.formatSql(values[variable], self.types[variable], self.sizes[variable])) | 238 sqlValues.append(self.formatSql(values[variable], self.types[variable], self.sizes[variable])) |
223 command = "INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join(sqlValues)) | 239 command = "INSERT INTO '%s' (%s) VALUES (%s)" % (self.name, ", ".join(self.variables), ", ".join(sqlValues)) |
224 id = self.mySqlConnection.executeQuery(command, True) | 240 id = self.mySqlConnection.executeQuery(command, True) |
329 Drop the content of the current table | 345 Drop the content of the current table |
330 """ | 346 """ |
331 query = self.mySqlConnection.executeQuery("SELECT * FROM '%s'" % (self.name)) | 347 query = self.mySqlConnection.executeQuery("SELECT * FROM '%s'" % (self.name)) |
332 print query.getLines() | 348 print query.getLines() |
333 | 349 |
334 |