<commit_before>/*
 * esqlite -- an erlang sqlite nif.
*/

#include <stdio.h> /* for debugging */
#include <erl_nif.h>

#include "sqlite3.h"

#define MAX_PATHNAME 512 /* unfortunately not in sqlite.h. */

static ERL_NIF_TERM _atom_ok;
static ERL_NIF_TERM _atom_error;

/*
 * Open database. Expects utf-8 input
*/
static ERL_NIF_TERM esqlite_open_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int rc;
    char filename[MAX_PATHNAME];
    sqlite3 *db;
   
    /* TODO ignore the utf-8 stuff for now */
    if(!enif_get_string(env, argv[0], filename, MAX_PATHNAME, ERL_NIF_LATIN1))
        return enif_make_badarg(env);   

    /* open the database */
    rc = sqlite3_open(filename, &db);
    if( rc ) {
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      sqlite3_close(db);
      /* maak een error tuple */
    }

    /* and wrap it in an erlang resource */
    fprintf(stderr, "The database is open.\n");

    sqlite3_close(db);

    fprintf(stderr, "And closed\n");
    
    return enif_make_tuple2(env, _atom_ok, _atom_ok);
}

<commit_msg>First test case<commit_after>/*
 * esqlite -- an erlang sqlite nif.
*/

#include <stdio.h> /* for debugging */
#include <erl_nif.h>

#include "sqlite3.h"

#define MAX_PATHNAME 512 /* unfortunately not in sqlite.h. */

static ERL_NIF_TERM _atom_ok;
static ERL_NIF_TERM _atom_error;

/*
 * Open database. Expects utf-8 input
*/
static ERL_NIF_TERM esqlite_open_nif(ErlNifEnv* env, int argc, const ERL_NIF_TERM argv[])
{
    int rc;
    char filename[MAX_PATHNAME];
    sqlite3 *db;
   
    /* TODO ignore the utf-8 stuff for now */
    if(!enif_get_string(env, argv[0], filename, MAX_PATHNAME, ERL_NIF_LATIN1))
        return enif_make_badarg(env);   

    /* open the database */
    rc = sqlite3_open(filename, &db);
    if( rc ) {
      fprintf(stderr, "Can't open database: %s\n", sqlite3_errmsg(db));
      sqlite3_close(db);
      /* maak een error tuple */
      return enif_make_tuple2(env, _atom_error, _atom_error); /* todo add error message */
    }

    /* and wrap it in an erlang resource */
    fprintf(stderr, "The database is open.\n");
    sqlite3_close(db);
    fprintf(stderr, "And closed\n");
    
    return enif_make_tuple2(env, _atom_ok, _atom_ok);
}


{'fraction_non_alphanumeric': 0.12627381479840497, 'fraction_numerical': 0.01284891448825875, 'mean_word_length': 3.1737523105360443, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '614068', 'n_tokens_mistral': 872, 'n_tokens_neox': 848, 'n_words': 210}