<commit_before>#include "gh-datastore.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

char *
gh_datastore_db_path (char *data_dir)
{
  char *db_file = "/ghighlighter.db";

  int length = strlen (data_dir);
  length = length + strlen (db_file);

  char *path = malloc (length + sizeof (char));
  path[0] = '\0';
  strcat (path, data_dir);
  strcat (path, db_file);

  return path;
}

void
gh_datastore_initialize_config_table (sqlite3 *db)
{
  char *create = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT);";
  sqlite3_exec (db, create, 0, 0, 0);
}

int
gh_datastore_get_db_version (sqlite3 *db)
{
  int version;
  char *select = "SELECT value FROM config WHERE key = 'db_version' LIMIT 1;";

  sqlite3_stmt *statement;
  sqlite3_prepare_v2 (db, select, -1, &statement, 0);

  int status = sqlite3_step (statement);
  if (status == SQLITE_ROW)
  {
    const char *value = (const char *) sqlite3_column_text (statement, 0);
    version = atoi (value);
  }
  else if (status == SQLITE_DONE)
  {
    gh_datastore_set_db_version (db, 0);
    version = 0;
  }

  return version;
}<commit_msg>Return -1 as default db version<commit_after>#include "gh-datastore.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>

char *
gh_datastore_db_path (char *data_dir)
{
  char *db_file = "/ghighlighter.db";

  int length = strlen (data_dir);
  length = length + strlen (db_file);

  char *path = malloc (length + sizeof (char));
  path[0] = '\0';
  strcat (path, data_dir);
  strcat (path, db_file);

  return path;
}

void
gh_datastore_initialize_config_table (sqlite3 *db)
{
  char *create = "CREATE TABLE IF NOT EXISTS config (key TEXT PRIMARY KEY, value TEXT);";
  sqlite3_exec (db, create, 0, 0, 0);
}

int
gh_datastore_get_db_version (sqlite3 *db)
{
  int version;
  char *select = "SELECT value FROM config WHERE key = 'db_version' LIMIT 1;";

  sqlite3_stmt *statement;
  sqlite3_prepare_v2 (db, select, -1, &statement, 0);

  int status = sqlite3_step (statement);
  if (status == SQLITE_ROW)
  {
    const char *value = (const char *) sqlite3_column_text (statement, 0);
    version = atoi (value);
  }
  else if (status == SQLITE_DONE)
  {
    gh_datastore_set_db_version (db, 0);
    version = -1;
  }

  return version;
}
{'fraction_non_alphanumeric': 0.13233348037053375, 'fraction_numerical': 0.017203352448169385, 'mean_word_length': 4.017699115044247, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '635598', 'n_tokens_mistral': 895, 'n_tokens_neox': 852, 'n_words': 239}