/* * 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(); } }
internal TsColumn(String s, java.util.Hashtable <Object, Object> tableDefs, String inputContext) //throws tinySQLException { FieldTokenizer ft, ftArgs; int j, numericType, nameLength, dotAt, argIndex; String upperName, checkName, nextArg; TinySQLTable jtbl; TsColumn tcol; java.util.Vector <Object> t; java.util.Enumeration <Object> col_keys; name = s; longName = name; nameLength = name.length(); contextList = new java.util.Vector <Object>(); contextList.addElement(inputContext); ft = new FieldTokenizer(name, '(', false); if (ft.countFields() == 2) { /* * This is a function rather than a simple column or constant */ functionName = ft.getField(0).toUpperCase(); if (functionName.equals("COUNT")) { type = java.sql.Types.INTEGER; size = 10; intValue = java.lang.Integer.MIN_VALUE; groupedColumn = true; } else if (functionName.equals("SUM")) { type = java.sql.Types.FLOAT; size = 10; groupedColumn = true; } else if (functionName.equals("TO_DATE")) { type = java.sql.Types.DATE; size = 10; } else if (functionName.equals("CONCAT") | functionName.equals("UPPER") | functionName.equals("SUBSTR") | functionName.equals("TRIM")) { type = java.sql.Types.CHAR; } functionArgString = ft.getField(1); ftArgs = new FieldTokenizer(functionArgString, ',', false); functionArgs = new java.util.Vector <Object>(); argIndex = 0; while (ftArgs.hasMoreFields()) { nextArg = ftArgs.nextField(); tcol = new TsColumn(nextArg, tableDefs, inputContext); if (tcol.isGroupedColumn()) { groupedColumn = true; } /* * MAX and MIN functions can be either FLOAT or CHAR types * depending upon the type of the argument. */ if (functionName.equals("MAX") | functionName.equals("MIN")) { if (argIndex > 0) { throw new TinySQLException("Function can only have 1 argument"); } groupedColumn = true; type = tcol.type; size = tcol.size; } else if (functionName.equals("CONCAT")) { type = java.sql.Types.CHAR; size += tcol.size; } else if (functionName.equals("UPPER")) { type = java.sql.Types.CHAR; size = tcol.size; } else if (functionName.equals("TO_DATE")) { type = java.sql.Types.DATE; size = 10; } else if (functionName.equals("TRIM")) { type = java.sql.Types.CHAR; size = tcol.size; } else if (functionName.equals("SUBSTR")) { type = java.sql.Types.CHAR; if (argIndex == 0 & tcol.type != java.sql.Types.CHAR) { throw new TinySQLException("SUBSTR first argument must be character"); } else if (argIndex == 1) { if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1) { throw new TinySQLException("SUBSTR second argument " + tcol.getString() + " must be integer > 0"); } } else if (argIndex == 2) { if (tcol.type != java.sql.Types.INTEGER | tcol.intValue < 1) { throw new TinySQLException("SUBSTR third argument " + tcol.getString() + " must be integer > 0"); } size = tcol.intValue; } } argIndex++; functionArgs.addElement(tcol); } } else { /* * Check for SYSDATE */ if (name.toUpperCase().equals("SYSDATE")) { isConstant = true; type = java.sql.Types.DATE; size = 10; notNull = true; valueSet = true; //Basties mote: not really SimpleDateFormat needed... - need yyyy-MM-dd // stringValue = fmtyyyyMMdd.format(today.getTime()); stringValue = System.DateTime.Today.ToString("yyyy-MM-dd"); /* * Check for a quoted string */ } else if (UtilString.isQuotedString(name)) { isConstant = true; type = java.sql.Types.CHAR; stringValue = UtilString.removeQuotes(name); if (stringValue != (String)null) { size = stringValue.length(); notNull = true; valueSet = true; } } else { /* * Check for a numeric constant */ numericType = UtilString.getValueType(name); if (numericType == java.sql.Types.INTEGER) { intValue = java.lang.Integer.valueOf(name).intValue(); size = 10; type = numericType; isConstant = true; notNull = true; valueSet = true; } else if (numericType == java.sql.Types.FLOAT) { floatValue = java.lang.Float.valueOf(name).floatValue(); size = 10; type = numericType; isConstant = true; notNull = true; valueSet = true; } else { /* * This should be a column name. */ columnTable = (TinySQLTable)null; upperName = name.toUpperCase(); if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("Trying to find table for " + upperName); } dotAt = upperName.indexOf("."); if (dotAt > -1) { tableName = upperName.substring(0, dotAt); if (tableDefs != (java.util.Hashtable <Object, Object>)null & tableName.indexOf("->") < 0) { t = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER"); tableName = UtilString.findTableAlias(tableName, t); } upperName = upperName.substring(dotAt + 1); /* * Check to see if this column name has a short equivalent. */ if (upperName.length() > 11) { longName = name; upperName = TinySQLGlobals.getShortName(upperName); } columnTable = (TinySQLTable)tableDefs.get(tableName); } else if (tableDefs != (java.util.Hashtable <Object, Object>)null) { /* * Check to see if this column name has a short equivalent. */ if (upperName.length() > 11) { longName = name; upperName = TinySQLGlobals.getShortName(upperName); } /* * Use an enumeration to go through all of the tables to find * this column. */ t = (java.util.Vector <Object>)tableDefs.get("TABLE_SELECT_ORDER"); for (j = 0; j < t.size(); j++) { tableName = (String)t.elementAt(j); jtbl = (TinySQLTable)tableDefs.get(tableName); col_keys = jtbl.column_info.keys(); /* * Check all columns. */ while (col_keys.hasMoreElements()) { checkName = (String)col_keys.nextElement(); if (checkName.equals(upperName)) { upperName = checkName; columnTable = jtbl; break; } } if (columnTable != (TinySQLTable)null) { break; } } } else { if (TinySQLGlobals.DEBUG) { java.lang.SystemJ.outJ.println("No table definitions."); } } if (columnTable != (TinySQLTable)null) { name = columnTable.table + "->" + columnTable.tableAlias + "." + upperName; type = columnTable.ColType(upperName); size = columnTable.ColSize(upperName); decimalPlaces = columnTable.ColDec(upperName); tableName = columnTable.table + "->" + columnTable.tableAlias; } } } } }