<commit_before>//
//  main.swift
//  sqljson
//
//  Created by <NAME> on 2015-06-04.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

enum Error:Int32 {
    case none = 0
    case databaseMissing
    case databaseOpen
    case bindRead
    case bindDeserialize
    case queryMissing
    case queryRead
    case queryExec
    case inputRead
    case inputDeserialize
    case inputFormat
    case keyMissing
    case outputSerialize
    case outputWrite
}

func + <K,V>(left: Dictionary<K,V>, right: Dictionary<K,V>)
    -> Dictionary<K,V>
{
    var map = Dictionary<K,V>()
    for (k, v) in left {
        map[k] = v
    }
    for (k, v) in right {
        map[k] = v
    }
    return map
}

func Fail(_ code:Error, message:String) -> Never  {
    let data = (message + "\n").data(using: String.Encoding.utf8)!
    FileHandle.standardError.write(data)
    exit(code.rawValue)
}

let parameters = UserDefaults.standard.dictionaryRepresentation()

guard let databasePath = (parameters["database"] as? String) else {
    Fail(Error.databaseMissing, message: "Error opening database: no path")
}

let database:SQLPRDatabase;
do {
    database = try SQLPRDatabase(path: databasePath, flags: SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, vfs: nil);
} catch let error as NSError {
    Fail(Error.databaseOpen, message: String(format:"Error opening database: %@: %@", databasePath, error.localizedDescription))
}

// Build bindings
var bindings = [String:AnyObject]()
let bindingsPath = parameters["bindings"] as? String
if let path = bindingsPath {
    let data: Data<commit_msg>Remove extra space.<commit_after>//
//  main.swift
//  sqljson
//
//  Created by <NAME> on 2015-06-04.
//  Copyright (c) 2015 <NAME>. All rights reserved.
//

import Foundation

enum Error:Int32 {
    case none = 0
    case databaseMissing
    case databaseOpen
    case bindRead
    case bindDeserialize
    case queryMissing
    case queryRead
    case queryExec
    case inputRead
    case inputDeserialize
    case inputFormat
    case keyMissing
    case outputSerialize
    case outputWrite
}

func + <K,V>(left: Dictionary<K,V>, right: Dictionary<K,V>)
    -> Dictionary<K,V>
{
    var map = Dictionary<K,V>()
    for (k, v) in left {
        map[k] = v
    }
    for (k, v) in right {
        map[k] = v
    }
    return map
}

func Fail(_ code:Error, message:String) -> Never {
    let data = (message + "\n").data(using: String.Encoding.utf8)!
    FileHandle.standardError.write(data)
    exit(code.rawValue)
}

let parameters = UserDefaults.standard.dictionaryRepresentation()

guard let databasePath = (parameters["database"] as? String) else {
    Fail(Error.databaseMissing, message: "Error opening database: no path")
}

let database:SQLPRDatabase;
do {
    database = try SQLPRDatabase(path: databasePath, flags: SQLITE_OPEN_CREATE | SQLITE_OPEN_READWRITE, vfs: nil);
} catch let error as NSError {
    Fail(Error.databaseOpen, message: String(format:"Error opening database: %@: %@", databasePath, error.localizedDescription))
}

// Build bindings
var bindings = [String:AnyObject]()
let bindingsPath = parameters["bindings"] as? String
if let path = bindingsPath {
    let data: Data
{'fraction_non_alphanumeric': 0.11416953393806693, 'fraction_numerical': 0.010009383797309979, 'mean_word_length': 3.4110344827586205, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 21, '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': '4592985', 'n_tokens_mistral': 1024, 'n_tokens_neox': 985, 'n_words': 287}