<commit_before>var fs = require('fs');
var {merge} = require('ringo/utils/objects');

var jar = fs.resolve(module.path, './jars/sqlite-jdbc-3.7.2.jar');
addToClasspath(jar);

var dm = java.sql.DriverManager;
dm.registerDriver(new org.sqlite.JDBC);

var Connection = function(path, options) {
    options = merge(options, {
        autocommit: true,
        column_names: true
    });

    this.column_names = options.column_names

    this.connection = dm.getConnection('jdbc:sqlite:' + path);
    this.connection.setAutoCommit(options.autocommit);
}

function prepare_statement(s, values) {
    values.forEach(function(value, index) {
        switch (typeof value) {
            case 'undefined':
                s.setNull(index + 1);
            case 'number':
                (parseFloat(value) == parseInt(value)) ?
                    s.setLong(index + 1, value) :
                    s.setDouble(index + 1, value);
                break;
            case 'boolean':
                s.setBoolean(index + 1, value);
                break;
            case 'object':
                if (value === null) {
                    s.setNull(index + 1);
                    break;
                }

                if (value instanceof Date) {
                    s.setDate(index + 1, new java.sql.Date(value));
                    break;
                }

                // otherwise, fall through to string default
            case 'string':
            default:
                s.setString(index + 1, value);
        }
    });
}

var {NULL, INTEGER, FLOAT, VARCHAR} = java.sql.Types;
function wrap_result(result_set, column_names) {
    var metadata = result_set.getMetaData();
    var column_count = metadata.getColumnCount();

    while (metadata.next()) {
        var row = [];

        for (var i = 1; i <= column_count; i++) {
            var type = metadata.getColumnType(i);
            var value = null;

            switch (type) {<commit_msg>New JDBC jar doesn't have the simpler setNull call. Also, fix bug when value is undefined.<commit_after>var fs = require('fs');
var {merge} = require('ringo/utils/objects');

var jar = fs.resolve(module.path, './jars/sqlite-jdbc-3.7.2.jar');
addToClasspath(jar);

var dm = java.sql.DriverManager;
dm.registerDriver(new org.sqlite.JDBC);

var Connection = function(path, options) {
    options = merge(options, {
        autocommit: true,
        column_names: true
    });

    this.column_names = options.column_names

    this.connection = dm.getConnection('jdbc:sqlite:' + path);
    this.connection.setAutoCommit(options.autocommit);
}

function prepare_statement(s, values) {
    values.forEach(function(value, index) {
        switch (typeof value) {
            case 'undefined':
                s.setNull(index + 1, java.sql.Types.NULL);
                break;
            case 'number':
                (parseFloat(value) == parseInt(value)) ?
                    s.setLong(index + 1, value) :
                    s.setDouble(index + 1, value);
                break;
            case 'boolean':
                s.setBoolean(index + 1, value);
                break;
            case 'object':
                if (value === null) {
                    s.setNull(index + 1, java.sql.Types.NULL);
                    break;
                }

                if (value instanceof Date) {
                    s.setDate(index + 1, new java.sql.Date(value));
                    break;
                }

                // otherwise, fall through to string default
            case 'string':
            default:
                s.setString(index + 1, value);
        }
    });
}

var {NULL, INTEGER, FLOAT, VARCHAR} = java.sql.Types;
function wrap_result(result_set, column_names) {
    var metadata = result_set.getMetaData();
    var column_count = metadata.getColumnCount();

    while (metadata.next()) {
        var row = [];

        for (var i = 1; i <= column_count; i++) {
            var type = metadata.getColumnType(i);
            var value = null;

            switch (type) {
{'fraction_non_alphanumeric': 0.12320987654320988, 'fraction_numerical': 0.005432098765432099, 'mean_word_length': 1.7427217332430602, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2506471', 'n_tokens_mistral': 1202, 'n_tokens_neox': 1124, 'n_words': 266}