<commit_before>#include "sqlOp.h"

bool SqlOp::openDatabase(std::string database_name)
{
  // Open Database
  dbName = database_name;
  try
  {
    if (sqlite3_open(database_name.c_str(), &db) == SQLITE_OK)
      return true;

    return false;
  }
  catch (std::string e)
  {
      std::cout << "An exception occurred. Exception : " << e.c_str() << '\n';
        return false;
   }

  /*std::cout << "Opening "<<database_name.c_str()<< std::endl;

  rc = sqlite3_open(database_name.c_str(), &db);
  if (rc)
  {
    std::cerr << "Error opening SQLite3 database: " << sqlite3_errmsg(db) << std::endl << std::endl;
    sqlite3_close(db);
    return false;
  }
  else
  {
    std::cout << "Opened "<<database_name.c_str() << std::endl << std::endl;
    return true;
  }*/
}

bool SqlOp::setLicence(std::string table_name, std::string licence, std::string user_name){
  openDatabase(dbName);
  std::string str = "UPDATE " + table_name + " SET usedBy = '"+user_name+"'  WHERE license like '" + licence + "';";
  char * ch = new char[str.length() + 1];
  std::strcpy(ch, str.c_str());
  query(ch);
  str = "UPDATE " + table_name + " SET inUse = '1' WHERE license like '"+licence+"';";
  std::strcpy(ch, str.c_str());
  query(ch);
  delete[] ch;
  closeDatabase();
  return true;
}

bool SqlOp::resetLicence(std::string table_name, std::string licence){
  openDatabase(dbName);
  std::string str = "UPDATE " + table_name + " SET usedBy = '' WHERE license like '" + licence + "';";
  char * ch = new char[str.length() + 1];
  std::strcpy(ch, str.c_str());
  query(ch);
  str = "UPDATE " + table_name + " SET inUse = '0' WHERE license like '" + licence + "';";
  std::strcpy(ch, str.c_str());
  query(ch);
  delete[] ch;
  closeDatabase();
  return true;
}<commit_msg>Revert "46 memory leaks before this"<commit_after>#include "sqlOp.h"

bool SqlOp::openDatabase(std::string database_name)
{
  // Open Database
<<<<<<< HEAD
  dbName = database_name;
  try
  {
    if (sqlite3_open(database_name.c_str(), &db) == SQLITE_OK)
      return true;

    return false;
  }
  catch (std::string e)
  {
      std::cout << "An exception occurred. Exception : " << e.c_str() << '\n';
        return false;
   }

  /*std::cout << "Opening "<<database_name.c_str()<< std::endl;
=======
  std::cout << "Opening "<<database_name.c_str()<< std::endl;
>>>>>>> parent of 0cc1d47... 46 memory leaks before this

  rc = sqlite3_open(database_name.c_str(), &db);
  if (rc)
  {
    std::cerr << "Error opening SQLite3 database: " << sqlite3_errmsg(db) << std::endl << std::endl;
    sqlite3_close(db);
    return false;
  }
  else
  {
    std::cout << "Opened "<<database_name.c_str() << std::endl << std::endl;
    return true;
  }
}

bool SqlOp::setLicence(std::string table_name, std::string licence, std::string user_name){
  openDatabase(dbName);
  std::string str = "UPDATE " + table_name + " SET usedBy = '"+user_name+"'  WHERE license like '" + licence + "';";
  char * ch = new char[str.length() + 1];
  std::strcpy(ch, str.c_str());
  query(ch);
  str = "UPDATE " + table_name + " SET inUse = '1' WHERE license like '"+licence+"';";
  std::strcpy(ch, str.c_str());
  query(ch);
  delete[] ch;
  closeDatabase();
  return true;
}

bool SqlOp::resetLicence(std::string table_name, std::string licence){
  openDatabase(dbName);
  std::string str = "UPDATE " + table_name + " SET usedBy = '' WHERE license like '" + licence + "';";
  char * ch = new char[str.length() + 1];
  std::strcpy(ch, str.c_str());
  query(ch);
  str = "UPDATE " + table_name + " SET inUse = '0' WHERE license like '" + licence + "';";
  std::strcpy(ch, str.c_str());
  query(ch);
  delete[] ch;
  closeDatabase();
  return true;
}
{'fraction_non_alphanumeric': 0.19081272084805653, 'fraction_numerical': 0.007067137809187279, 'mean_word_length': 3.8293963254593177, 'pattern_counts': {'":': 0, '<': 72, '<?xml version=': 0, '>': 10, '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': '3711877', 'n_tokens_mistral': 1370, 'n_tokens_neox': 1331, 'n_words': 308}