Update records in a database table from the main dataframe
761679
def update_table(self, table, pks=['id']):
        
        if self._check_db() is False:
            return
        try:
            table = self.db[table]
        except Exception as e:
            self.err(e, "Can not find table " + table)
        if self.db is None:
            msg = "Please connect a database before or provide a database url"
            self.err(msg)
            return
        recs = self.to_records_()
        for rec in recs:
            table.insert_ignore(rec, pks, ensure=True)
        self.ok("Data updated in table", table)
658586
private void updateTable()
  {
    try
    {
      tableModel = new DefaultTableModel(new String[]
        {
          "name", "id", "text", "tokens", "source_path"
        }, 0);
      tableList.setModel(tableModel);

      List<Map<String, Object>> stats = corpusAdmin.listCorpusStats();

      for(Map<String, Object> map : stats)
      {
        String[] rowData = new String[tableModel.getColumnCount()];
        for(int j = 0; j < rowData.length; j++)
        {
          String cName = tableList.getColumnName(j);
          if(map.containsKey(cName))
          {
            rowData[j] = map.get(cName).toString();
          }
          else
          {
            rowData[j] = "";
          }
        }

        tableModel.addRow(rowData);
      }
    }
    catch(Exception ex)
    {
      ImportStatus importStatus = corpusAdmin.getAdministrationDao().initImportStatus();
      importStatus.addException("list corpora exception", ex);
      new ExceptionDialog(importStatus).setVisible(true);
    }
  }
931770
def upsert(self, table: str, record: dict, create_cols: bool=False,
               dtypes: list=None, pks=["id"], namefields=["id"]):
        
        try:
            self.db[table].upsert(record, pks, create_cols, dtypes)
        except Exception as e:
            self.err(e, "Can not upsert data")
            return
        names = ""
        for el in namefields:
            names += " " + record[el]
        self.ok("Upserted record"+names)
66169
def from_dataframe(cls, name, df, indices, primary_key=None):
        """"""

        # ordered list (column_name, column_type) pairs
        column_types = []
        # which columns have nullable values
        nullable = set()

        # tag cached database by dataframe's number of rows and columns
        for column_name in df.columns:
            values = df[column_name]
            if values.isnull().any():
                nullable.add(column_name)
            column_db_type = db_type(values.dtype)
            column_types.append((column_name.replace(" ", "_"), column_db_type))

        def make_rows():
            return list(tuple(row) for row in df.values)

        return cls(
            name=name,
            column_types=column_types,
            make_rows=make_rows,
            indices=indices,
            nullable=nullable,
            primary_key=primary_key)
155957
def update(self, columns=(), by=(), where=(), **kwds):
        
        return self._seu('update', columns, by, where, kwds)
197580
def from_dataframe(dataframe, table_name=""):
        

        return TableData(table_name, list(dataframe.columns.values), dataframe.values.tolist())
1338088
def insert(self, table, records, create_cols=False, dtypes=None):
        
        if self._check_db() is False:
            return
        try:
            table = self.db[table]
        except Exception as e:
            self.err(e, "Can not find table " + table)
        t = type(records)
        if t == dict:
            func = table.insert
        elif t == list:
            func = table.insert_many
        else:
            msg = "Rows datatype " + \
                str(t) + " not valid: use a list or a dictionary"
            self.err(msg)
        if create_cols is True:
            try:
                func(records, ensure=True, types=dtypes)
            except Exception as e:
                self.err(e, "Can not insert create columns and insert data")
            return
        else:
            try:
                func(records, types=dtypes)
            except Exception as e:
                self.err(e, "Can not insert data")
            return
        self.ok("Rows inserted in the database")
165348
def update(self, **data):
        
        data = data.items()
        update_command_arg = ", ".join("{} = ?".format(entry[0])
                                       for entry in data)
        cmd = "update {table} set {update_command_arg} {where_clause}".format(
            update_command_arg=update_command_arg,
            where_clause=self.where_clause,
            table=self.table_name).rstrip()
        Repo.db.execute(cmd, [entry[1] for entry in data] + self.where_values)
122831
def update(self,table, sys_id, **kparams):
        
        record = self.api.update(table, sys_id, **kparams)
        return record
17219
def insert_multiple_records(self,
                                table: str,
                                fields: Sequence[str],
                                records: Sequence[Sequence[Any]]) -> int:
        """"""
        self.ensure_db_open()
        sql = self.localize_sql(get_sql_insert(table, fields,
                                               self.get_delims()))
        log.debug("About to insert multiple records with SQL template: " + sql)
        try:
            cursor = self.db.cursor()
            debug_sql(sql, records)
            cursor.executemany(sql, records)
            # ... binds the placeholders (?, %s) to values in the process
            # http://www.python.org/dev/peps/pep-0249/
            log.debug("Records inserted.")
            return cursor.rowcount
        except:  # nopep8
            log.exception("insert_multiple_records: Failed to insert records.")
            raise
399412
def _updateColumnValues(self, index, hidden):
        
        if hidden or not self.isVisible():
            return
        
        column = self.columnOf(index)
        if not column in self._loadedColumns:
            self._loadedColumns.add(column)
            
            records = self.collectRecords()
            self.loadColumnsRequested.emit(records, column)
98120
def loadColumns(self, records, columnName):
        
        try:
            for record in records:
                col = record.schema().column(columnName)
                if not col:
                    continue
                
                value = record.recordValue(col.name(), autoInflate=True)
                self.columnLoaded.emit(record, col.name(), wrapNone(value))
        
        except ConnectionLostError:
            self.connectionLost.emit()
        
        except Interruption:
            pass
1086971
def update(self,table, sys_id, **kparams):
        
        result = self.table_api_put(table, sys_id, **kparams)
        return self.to_record(result, table)
215577
def capture_update(self, *, update_fields=()):
        """"""
        return self.capture_update_from_model(self.table_name, self.record_id,
                                              update_fields=update_fields)
104572
public void init(BaseDatabase database, Record record)
    {
        super.init(database, record);
        if (((QueryRecord)record).getBaseRecord() != null)
            m_tableNext = ((QueryRecord)record).getBaseRecord().getTable();   // Pass most commands thru to the main record's table
    }
304411
def _update_rows(self):
        
        for row, item in enumerate(self._items):
            item.row = row  # Row is the Parent item
            item.column = 0
        
        for column, item in enumerate(self._columns):
            item.row = self.row  # Row is the Parent item
            item.column = column
470112
private void updateTable(Connection connection) throws DatabaseException {
        try {
			// Add the SOURCEHISTORYID column to the db if necessary
			if (!DbUtils.hasColumn(connection, TABLE_NAME, SOURCEHISTORYID)) {
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+SOURCEHISTORYID+" INT DEFAULT 0");
			}
			
			// Add the ATTACK column to the db if necessary
			if (!DbUtils.hasColumn(connection, TABLE_NAME, ATTACK)) {
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+ATTACK+" VARCHAR(32768) DEFAULT ''");
			}
			
			if (!DbUtils.hasColumn(connection, TABLE_NAME, EVIDENCE)) {
				// Evidence, cweId and wascId all added at the same time
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+EVIDENCE+" VARCHAR(16777216) DEFAULT ''");
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+CWEID+" INT DEFAULT -1");
			    DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+WASCID+" INT DEFAULT -1");
			}
			
			if (!DbUtils.hasIndex(connection, TABLE_NAME, ALERT_INDEX)) {
				// this speads up session loading
				DbUtils.execute(connection, "CREATE INDEX "+ALERT_INDEX+" ON "+TABLE_NAME+" ("+SOURCEHISTORYID+")");
			}

			if (!DbUtils.hasColumn(connection, TABLE_NAME, SOURCEID)) {
				DbUtils.execute(connection, "ALTER TABLE "+TABLE_NAME+" ADD COLUMN "+SOURCEID+" INT DEFAULT 0");
				DbUtils.execute(connection, "CREATE INDEX INDEX_ALERT_SOURCEID ON "+TABLE_NAME+" ("+SOURCEID+")");
			}
		} catch (SQLException e) {
			throw new DatabaseException(e);
		}
        
    }