/* * Update rows which match a WHERE clause */ private void UpdateStatement(String tableName, java.util.Vector <Object> c, java.util.Vector <Object> v, TinySQLWhere wc) //throws TinySQLException { /* * Create a table object and put it in the Hashtable. */ TinySQLTable jtbl = getTable(tableName); java.util.Hashtable <Object, Object> tables = new java.util.Hashtable <Object, Object>(); tables.put(tableName, jtbl); String columnName, columnString, whereStatus; /* * Process each row in the table ignoring deleted rows. */ jtbl.GoTop(); while (jtbl.NextRecord()) { if (!jtbl.isDeleted()) { java.util.Enumeration <Object> cols = jtbl.column_info.keys(); whereStatus = "TRUE"; while (cols.hasMoreElements()) { /* * Use the table name for the table alias for updates. */ columnName = jtbl.table + "->" + jtbl.table + "." + (String)cols.nextElement(); columnString = jtbl.GetCol(columnName); /* * Check the status of the where clause for each column value. */ if (wc != (TinySQLWhere)null) { whereStatus = wc.evaluate(columnName, columnString); } if (whereStatus.equals("FALSE")) { break; } } if (whereStatus.equals("TRUE")) { jtbl.UpdateCurrentRow(c, v); } if (wc != (TinySQLWhere)null) { wc.clearValues(jtbl.table + "->" + jtbl.tableAlias); } } } jtbl.close(); }
/* * Create the tinySQLTable object, then insert a row, and update * it with the c and v Vectors */ private void InsertStatement(String statementType, String tableName, java.util.Vector <Object> c, java.util.Vector <Object> v) //throws TinySQLException { String columnName, valueString; int i, columnType, columnSize; double value; insertTable = getTable(tableName); /* * Check that the values supplied are the correct type and length. */ for (i = 0; i < c.size(); i++) { columnName = (String)c.elementAt(i); valueString = (String)v.elementAt(i); if (valueString == (String)null) { continue; } valueString = UtilString.removeQuotes(valueString); valueString = UtilString.replaceAll(valueString, "''", "'"); columnType = insertTable.ColType(columnName); if (Utils.isNumberColumn(columnType)) { try { value = java.lang.Double.parseDouble(valueString); } catch (Exception) { throw new TinySQLException("Insert failed: column " + columnName + " is numeric - found " + valueString); } } else if (Utils.isDateColumn(columnType)) { try { /* * Modify the input to be the standard YYYYMMDD format */ if (valueString.trim().length() > 0) { v.setElementAt(UtilString.dateValue(valueString), i); } } catch (Exception e) { throw new TinySQLException("Insert failed: " + e.getMessage()); } } columnSize = insertTable.ColSize(columnName); if (valueString.length() > columnSize) { throw new TinySQLException("Insert failed: string too long for " + " column " + columnName + " " + java.lang.Integer.toString(valueString.length()) + " > " + java.lang.Integer.toString(columnSize) + "<" + valueString + ">"); } } insertTable.InsertRow(c, v); /* * Close the table file that has just been updated unless this is a * PreparedStatement. In that case an explicit close must be done * on the statement object to close any open files. */ if (!statementType.endsWith("tinySQLPreparedStatement")) { insertTable.close(); } }