<commit_before>local DBI, dbh = require 'DBI'

function db_connect(db_id)
  if db_id == nil then db_id = 'default' end

  local connection = settings.db[db_id]

  if connection == nil then return end

  if not connection.autocommit then connection.autocommit = true end

  dbh = assert(DBI.Connect(
    connection.driver,
    connection.database,
    connection.username,
    connection.password,
    connection.host,
    connection.port
  ))

  -- commit the transaction
  dbh:autocommit(connection.autocommit)

  -- check status of the connection
  return dbh:ping()
end

function db_query(query, ...)
  if dbh == nil then return end

  -- prepare a query
  local sth = assert(dbh:prepare(query))

  -- execute select with a bind variable
  sth:execute(...)

  return sth
end
<commit_msg>Add error message to output of function db_query().<commit_after>local DBI, dbh = require 'DBI'

function db_connect(db_id)
  if db_id == nil then db_id = 'default' end

  local connection = settings.db[db_id]

  if connection == nil then return end

  if not connection.autocommit then connection.autocommit = true end

  dbh = assert(DBI.Connect(
    connection.driver,
    connection.database,
    connection.username,
    connection.password,
    connection.host,
    connection.port
  ))

  -- commit the transaction
  dbh:autocommit(connection.autocommit)

  -- check status of the connection
  return dbh:ping()
end

function db_query(query, ...)
  if dbh == nil then return end

  -- prepare a query
  local sth = assert(dbh:prepare(query))

  -- execute select with a bind variable
  local success, err = sth:execute(...)

  return sth, err
end

{'fraction_non_alphanumeric': 0.0948905109489051, 'fraction_numerical': 0.0, 'mean_word_length': 3.375, 'pattern_counts': {'":': 0, '<': 3, '<?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': '1164428', 'n_tokens_mistral': 524, 'n_tokens_neox': 503, 'n_words': 159}