/** * Verify that calling {@link ParameterUtils#splitParameter(String)} when the parameter string has * a single item will return an string array with just that item. */ @Test public void testOneItem() { final String[] result = ParameterUtils.splitParameter("manifest.json"); assertNotNull(result); assertEquals(1, result.length); assertEquals("manifest.json", result[0]); }
/** * Some prepared statements return multiple results; the execute method handles these complex * statements as well as the simpler form of statements handled by executeQuery and executeUpdate. * * @exception SQLException if a database-access error occurs. * @see Statement#execute */ public boolean execute(Tds tds) throws SQLException { // // TDS can handle prepared statements by creating a temporary // procedure. Since procedure must have the datatype specified // in the procedure declaration we will have to defer creating // the actual procedure until the statement is executed. By // that time we know all the types of all of the parameters. // Procedure procedure = null; boolean result = false; // SAfe No need for this either. We'll have to consume all input, nut // just the last ResultSet (if one exists). // closeResults(false); // SAfe No need for this. getMoreResults sets it to -1 at start, anyway // updateCount = -2; // First make sure the caller has filled in all the parameters. ParameterUtils.verifyThatParametersAreSet(parameterList); // Find a stored procedure that is compatible with this set of parameters if one exists. procedure = findCompatibleStoredProcedure(tds, rawQueryString); // now look in tds // if we don't have a suitable match then create a new temporary stored procedure if (procedure == null) { // Create the stored procedure procedure = new Procedure(rawQueryString, tds.getUniqueProcedureName(), parameterList, tds); // SAfe Submit it to the SQL Server before adding it to the cache or procedures of transaction // list. // Otherwise, if submitProcedure fails (e.g. because of a syntax error) it will be in our // procedure // cache, but not on the server. submitProcedure(tds, procedure); // store it in the procedureCache tds.procedureCache.put(rawQueryString, procedure); // MJH Only record the proc name in proceduresOfTra if in manual commit mode if (!getConnection().getAutoCommit()) // MJH tds.proceduresOfTra.add(procedure); } result = internalExecuteCall( procedure.getProcedureName(), procedure.getParameterList(), parameterList, tds, warningChain); return result; }
/** * Verify that calling {@link ParameterUtils#splitParameter(String)} when the parameter string has * multiple items and whitespace will return an string array with those items stripped of the * leading and trailing whitespace. */ @Test public void testMultipleItemsWithWhitespace() { final String[] result = ParameterUtils.splitParameter(" manifest.json, popup.html, popup.js ,\nicon.png\t"); assertNotNull(result); assertEquals(4, result.length); assertEquals("manifest.json", result[0]); assertEquals("popup.html", result[1]); assertEquals("popup.js", result[2]); assertEquals("icon.png", result[3]); }
public PreparedStatement_base(TdsConnection conn_, String sql, int type, int concurrency) throws SQLException { super(conn_, type, concurrency); rawQueryString = conn_.nativeSQL(sql); int i; int numberOfParameters = ParameterUtils.countParameters(rawQueryString); parameterList = new ParameterListItem[numberOfParameters]; for (i = 0; i < numberOfParameters; i++) parameterList[i] = new ParameterListItem(); }
/** * Some prepared statements return multiple results; the execute method handles these complex * statements as well as the simpler form of statements handled by executeQuery and executeUpdate. * * @exception SQLException if a database-access error occurs. * @see Statement#execute */ public boolean execute(Tds tds) throws SQLException { // // TDS can handle prepared statements by creating a temporary // procedure. Since procedure must have the datatype specified // in the procedure declaration we will have to defer creating // the actual procedure until the statement is executed. By // that time we know all the types of all of the parameters. // Procedure procedure = null; boolean result = false; closeResults(); updateCount = -2; // First make sure the caller has filled in all the parameters. ParameterUtils.verifyThatParametersAreSet(parameterList); // Find a stored procedure that is compatible with this set of // parameters if one exists. procedure = findCompatibleStoredProcedure(tds, rawQueryString); // now look in tds // if we don't have a suitable match then create a new // temporary stored procedure if (procedure == null) { // create the stored procedure procedure = new Procedure(rawQueryString, tds.getUniqueProcedureName(), parameterList, tds); // store it in the procedureCache // procedureCache.addElement(procedure); // store it in the procedureCache tds.procedureCache.put(rawQueryString, procedure); tds.proceduresOfTra.add(procedure); // create it on the SQLServer. submitProcedure(tds, procedure); } result = executeCall( tds, procedure.getProcedureName(), procedure.getParameterList(), // formal params parameterList); // actual params return result; }
/** * Verify that calling {@link ParameterUtils#splitParameter(String)} with a blank string returns * {@code null}. */ @Test public void testBlank() { final String[] result = ParameterUtils.splitParameter(" \t\n"); assertNull(result); }
/** * Verify that calling {@link ParameterUtils#splitParameter(String)} with an empty string returns * {@code null}. */ @Test public void testEmpty() { final String[] result = ParameterUtils.splitParameter(""); assertNull(result); }