View | Details | Raw Unified | Return to bug 60066
Collapse All | Expand All

(-)a/bin/jmeter.properties (+3 lines)
Lines 823-828 wmlParser.types=text/vnd.wap.wml Link Here
823
823
824
# String used to indicate a null value
824
# String used to indicate a null value
825
#jdbcsampler.nullmarker=]NULL[
825
#jdbcsampler.nullmarker=]NULL[
826
#
827
# Max size of BLOBs and CLOBs to store in JDBC sampler. Result will be cut off
828
#jdbcsampler.max_retain_result_size=65536
826
829
827
#---------------------------------------------------------------------------
830
#---------------------------------------------------------------------------
828
# OS Process Sampler configuration
831
# OS Process Sampler configuration
(-)a/src/protocol/jdbc/org/apache/jmeter/protocol/jdbc/AbstractJDBCTestElement.java (-13 / +63 lines)
Lines 23-29 import java.io.UnsupportedEncodingException; Link Here
23
import java.lang.reflect.Field;
23
import java.lang.reflect.Field;
24
import java.math.BigDecimal;
24
import java.math.BigDecimal;
25
import java.nio.charset.StandardCharsets;
25
import java.nio.charset.StandardCharsets;
26
import java.sql.Blob;
26
import java.sql.CallableStatement;
27
import java.sql.CallableStatement;
28
import java.sql.Clob;
27
import java.sql.Connection;
29
import java.sql.Connection;
28
import java.sql.Date;
30
import java.sql.Date;
29
import java.sql.PreparedStatement;
31
import java.sql.PreparedStatement;
Lines 35-45 import java.sql.Time; Link Here
35
import java.sql.Timestamp;
37
import java.sql.Timestamp;
36
import java.sql.Types;
38
import java.sql.Types;
37
import java.util.ArrayList;
39
import java.util.ArrayList;
38
import java.util.Collection;
39
import java.util.HashMap;
40
import java.util.HashMap;
40
import java.util.List;
41
import java.util.List;
41
import java.util.Map;
42
import java.util.Map;
42
43
44
import org.apache.commons.io.IOUtils;
43
import org.apache.jmeter.samplers.SampleResult;
45
import org.apache.jmeter.samplers.SampleResult;
44
import org.apache.jmeter.save.CSVSaveService;
46
import org.apache.jmeter.save.CSVSaveService;
45
import org.apache.jmeter.testelement.AbstractTestElement;
47
import org.apache.jmeter.testelement.AbstractTestElement;
Lines 124-129 public abstract class AbstractJDBCTestElement extends AbstractTestElement implem Link Here
124
    private String resultVariable = ""; // $NON-NLS-1$
126
    private String resultVariable = ""; // $NON-NLS-1$
125
    private String queryTimeout = ""; // $NON-NLS-1$
127
    private String queryTimeout = ""; // $NON-NLS-1$
126
128
129
    private static final int MAX_RETAIN_SIZE = JMeterUtils.getPropDefault("jdbcsampler.max_retain_result_size", 64 * 1024);
130
127
    /**
131
    /**
128
     * Creates a JDBCSampler.
132
     * Creates a JDBCSampler.
129
     */
133
     */
Lines 283-298 public abstract class AbstractJDBCTestElement extends AbstractTestElement implem Link Here
283
                    if (name.length()>0){ // Save the value in the variable if present
287
                    if (name.length()>0){ // Save the value in the variable if present
284
                        Object o = outputValues.get(i);
288
                        Object o = outputValues.get(i);
285
                        if( o instanceof java.sql.ResultSet ) { 
289
                        if( o instanceof java.sql.ResultSet ) { 
286
                            ResultSet resultSet = (ResultSet) o;
290
                            putIntoVar(jmvars, name, (java.sql.ResultSet) o);
287
                            if(RS_STORE_AS_OBJECT.equals(resultSetHandler)) {
291
                        } else if (o instanceof java.sql.Clob) {
288
                                jmvars.putObject(name, o);
292
                            putIntoVar(jmvars, name, (java.sql.Clob) o);
289
                            }
293
                        } else if (o instanceof java.sql.Blob) {
290
                            else if( RS_COUNT_RECORDS.equals(resultSetHandler)) {
294
                            putIntoVar(jmvars, name, (java.sql.Blob) o);
291
                                jmvars.put(name,o.toString()+" "+countRows(resultSet)+" rows");
292
                            }
293
                            else {
294
                                jmvars.put(name, o.toString());
295
                            }
296
                        }
295
                        }
297
                        else {
296
                        else {
298
                            jmvars.put(name, o == null ? null : o.toString());
297
                            jmvars.put(name, o == null ? null : o.toString());
Lines 303-309 public abstract class AbstractJDBCTestElement extends AbstractTestElement implem Link Here
303
        }
302
        }
304
        return sb.toString();
303
        return sb.toString();
305
    }
304
    }
306
    
305
306
    private void putIntoVar(final JMeterVariables jmvars, final String name,
307
            final ResultSet resultSet) throws SQLException {
308
        if (RS_STORE_AS_OBJECT.equals(resultSetHandler)) {
309
            jmvars.putObject(name, resultSet);
310
        } else if (RS_COUNT_RECORDS.equals(resultSetHandler)) {
311
            jmvars.put(name, resultSet.toString() + " " + countRows(resultSet)
312
                    + " rows");
313
        } else {
314
            jmvars.put(name, resultSet.toString());
315
        }
316
    }
317
318
    private void putIntoVar(final JMeterVariables jmvars, final String name,
319
            final Clob clob) throws SQLException {
320
        try {
321
            if (clob.length() > MAX_RETAIN_SIZE) {
322
                jmvars.put(
323
                        name,
324
                        IOUtils.toString(clob.getCharacterStream(0,
325
                                MAX_RETAIN_SIZE))
326
                                + "<result cut off, it is too big>");
327
            } else {
328
                jmvars.put(name, IOUtils.toString(clob.getCharacterStream()));
329
            }
330
        } catch (IOException e) {
331
            log.warn("Could not read CLOB into " + name, e);
332
        }
333
    }
334
335
    private void putIntoVar(final JMeterVariables jmvars, final String name,
336
            final Blob blob) throws SQLException {
337
        if (RS_STORE_AS_OBJECT.equals(resultSetHandler)) {
338
            try {
339
                long length = Math.max(blob.length(), MAX_RETAIN_SIZE);
340
                jmvars.putObject(name,
341
                        IOUtils.toByteArray(blob.getBinaryStream(0, length)));
342
            } catch (IOException e) {
343
                log.warn("Could not read BLOB into " + name + " as object.", e);
344
            }
345
        } else if (RS_COUNT_RECORDS.equals(resultSetHandler)) {
346
            jmvars.put(name, blob.length() + " bytes");
347
        } else {
348
            try {
349
                long length = Math.max(blob.length(), MAX_RETAIN_SIZE);
350
                jmvars.put(name, IOUtils.toString(
351
                        blob.getBinaryStream(0, length), ENCODING));
352
            } catch (IOException e) {
353
                log.warn("Can't convert BLOB to String using " + ENCODING, e);
354
            }
355
        }
356
    }
357
307
    /**
358
    /**
308
     * Count rows in result set
359
     * Count rows in result set
309
     * @param resultSet {@link ResultSet}
360
     * @param resultSet {@link ResultSet}
310
- 

Return to bug 60066