<commit_before>/************************************ ABOUT ***********************************\
| This file is used to compile the db_schema.json file into any nessasary      |
| formats including                                                            |
| SQL Initilizer Query (For both MySQL and SQLite3)                            |
| C++ object to store a row of the database for easy access                    |
| Java object to store a row of the databasae for easy access (android)        |
| - Eventually there may be javascript support for the firefox / chrome        |
| plugins                                                                      |
\******************************************************************************/
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
// #include <boost/date.hpp>
#include <iostream>
#include <vector>
#include <sstream>
#include <map>

#include <stdlib.h>

using namespace std;


// Mapping of each SQL datatype to the corrisponding C++ datatype
map <string, string> SQLtoCPP {
    {"varchar", "std::string"},
    {"int", "int"},
    {"timestamp", "std::string"}
};

// Mapping of each sql datatype to the C++ sqlite3 function to get that type from the database
map <string, string> SQLITEtoCPP{
    {"varchar", "std::string(reinterpret_cast<const char*> (sqlite3_column_text (statement,i)))"},
    {"int", "sqlite3_column_int (statement,i)"},
    {"timestamp", "std::string(reinterpret_cast<const char*> (sqlite3_column_text (statement,i)))" } // Timestamp
};

// Mapping of each SQL datatype to the corrisponding Java datatype
map <string, string> SQLtoJava {
    {"varchar", "String"},
    {"int", "Integer"},
    {"timestamp", "String"}
};


int main() {
    cout << "Loading the JSON file" << endl;
    using boost::property_tree::ptree;
    ptree pt;

    // Load the JSON into the property tree ometrherfke
    string testfile = "db_schema.json";
    read_json(testfile, pt);

    cout << "JSON file loaded" << endl;



    cout << "Parsing File" << endl;

    stringstream CPPVariables;        // Really these should all be files
    stringstream CPPConstructor; // the construction for initilizing all of the variables from a sqlite3 statement
    stringstream SQLRows;    // to be joined and encapsulated
    stringstream SQLITERows; // special formatting for sqlite (no extra data, no newlines)
    vector<string> SQLIndexes; // to be joined as is

    // Pre loop constructors
    SQLRows << "CREATE TABLE rules (";
    SQLITERows << "CREATE TABLE rules ("; 

    // Allow tracking of the number of columns
    int columnCount = 0; 

    // Loop Constructors
    string concatinator = "";
    for ( ptree::value_type const& v : pt.get_child("columns")) {

        string columnName = v.first;

        ptree subtree = v.second;
        string type = subtree.get<std::string>("Type");
        string size = subtree.get("Size", "");
        string description = subtree.get("Description", "");
        string indexName = subtree.get("Index", "");
        string defaultValue = subtree.get("Default", "");
        bool isNullable = subtree.get("Nullable", true);
        string extraData = subtree.get("Extra", "");
        bool isDepricated = subtree.get("Depricated", false);

        // SQL colum Value
        SQLRows << concatinator << endl << "  `" << boost::to_lower_copy(columnName) << "`";
        SQLRows << " " << boost::to_lower_copy(type); if (size.length() > 0) SQLRows << "(" << size << ")"; SQLRows << " ";
        if (!isNullable) SQLRows << "NOT NULL";
        if (defaultValue.length() > 0) SQLRows << " DEFAULT " << defaultValue;
        if (extraData.length() > 0) SQLRows << " " << extraData;
        concatinator = ",";

        //SQLITE3 Constructor (no extra data, no newlines)
        SQLITERows << concatinator << " `" << boost::to_lower_copy(columnName) << "`";
        SQLITERows << " " << boost::to_lower_copy(type); if (size.length() > 0) SQLITERows << "\\(" << size << "\\)"; SQLITERows << " ";
        if (!isNullable) SQLITERows << "NOT NULL";
        if (defaultValue.length() > 0) SQLITERows << " DEFAULT " << defaultValue;
        concatinator = ",";

        // C++ Datatype variables
        CPPVariables << "\t" << SQLtoCPP[type] << " " << columnName << ";" << endl;

        // C++ SQLITE3 CONVERSIONS
        CPPConstructor << "\t\t\tif (columnName == \"" << boost::to_lower_copy(columnName) << "\") {" << columnName << " = " << SQLITEtoCPP[type] << ";}" << endl;

        // CREATE TABLE `virtual_aliases` (
        //   `id` int(11) NOT NULL auto_increment,
        //   `domain_id` int(11) NOT NULL,
        //   `source` varchar(100) NOT NULL,
        //   `destination` varchar(100) NOT NULL,
        //   PRIMARY KEY (`id`),
        //   FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
        // ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
        columnCount++;
    }

    // Post Loop Constst    ructors<commit_msg>switched the autogenerated cpp file to use spaces instead of tabs<commit_after>/************************************ ABOUT ***********************************\
| This file is used to compile the db_schema.json file into any nessasary      |
| formats including                                                            |
| SQL Initilizer Query (For both MySQL and SQLite3)                            |
| C++ object to store a row of the database for easy access                    |
| Java object to store a row of the databasae for easy access (android)        |
| - Eventually there may be javascript support for the firefox / chrome        |
| plugins                                                                      |
\******************************************************************************/
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/json_parser.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/regex.hpp>
// #include <boost/date.hpp>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <map>

#include <stdlib.h>

using namespace std;


// Mapping of each SQL datatype to the corrisponding C++ datatype
map <string, string> SQLtoCPP {
    {"varchar", "std::string"},
    {"int", "int"},
    {"timestamp", "std::string"}
};

// Mapping of each sql datatype to the C++ sqlite3 function to get that type from the database
map <string, string> SQLITEtoCPP{
    {"varchar", "std::string(reinterpret_cast<const char*> (sqlite3_column_text (statement,i)))"},
    {"int", "sqlite3_column_int (statement,i)"},
    {"timestamp", "std::string(reinterpret_cast<const char*> (sqlite3_column_text (statement,i)))" } // Timestamp
};

// Mapping of each SQL datatype to the corrisponding Java datatype
map <string, string> SQLtoJava {
    {"varchar", "String"},
    {"int", "Integer"},
    {"timestamp", "String"}
};


int main() {
    cout << "Loading the JSON file" << endl;
    using boost::property_tree::ptree;
    ptree pt;

    // Load the JSON into the property tree ometrherfke
    string testfile = "db_schema.json";
    read_json(testfile, pt);

    cout << "JSON file loaded" << endl;



    cout << "Parsing File" << endl;

    stringstream CPPVariables;        // Really these should all be files
    stringstream CPPConstructor; // the construction for initilizing all of the variables from a sqlite3 statement
    stringstream SQLRows;    // to be joined and encapsulated
    stringstream SQLITERows; // special formatting for sqlite (no extra data, no newlines)
    vector<string> SQLIndexes; // to be joined as is

    // Pre loop constructors
    SQLRows << "CREATE TABLE rules (";
    SQLITERows << "CREATE TABLE rules ("; 

    // Allow tracking of the number of columns
    int columnCount = 0; 

    // Loop Constructors
    string concatinator = "";
    for ( ptree::value_type const& v : pt.get_child("columns")) {

        string columnName = v.first;

        ptree subtree = v.second;
        string type = subtree.get<std::string>("Type");
        string size = subtree.get("Size", "");
        string description = subtree.get("Description", "");
        string indexName = subtree.get("Index", "");
        string defaultValue = subtree.get("Default", "");
        bool isNullable = subtree.get("Nullable", true);
        string extraData = subtree.get("Extra", "");
        bool isDepricated = subtree.get("Depricated", false);

        // SQL colum Value
        SQLRows << concatinator << endl << "  `" << boost::to_lower_copy(columnName) << "`";
        SQLRows << " " << boost::to_lower_copy(type); if (size.length() > 0) SQLRows << "(" << size << ")"; SQLRows << " ";
        if (!isNullable) SQLRows << "NOT NULL";
        if (defaultValue.length() > 0) SQLRows << " DEFAULT " << defaultValue;
        if (extraData.length() > 0) SQLRows << " " << extraData;
        concatinator = ",";

        //SQLITE3 Constructor (no extra data, no newlines)
        SQLITERows << concatinator << " `" << boost::to_lower_copy(columnName) << "`";
        SQLITERows << " " << boost::to_lower_copy(type); if (size.length() > 0) SQLITERows << "\\(" << size << "\\)"; SQLITERows << " ";
        if (!isNullable) SQLITERows << "NOT NULL";
        if (defaultValue.length() > 0) SQLITERows << " DEFAULT " << defaultValue;
        concatinator = ",";

        // C++ Datatype variables
        CPPVariables << "    " << SQLtoCPP[type] << " " << columnName << ";" << endl;

        // C++ SQLITE3 CONVERSIONS
        CPPConstructor << "            if (columnName == \"" << boost::to_lower_copy(columnName) << "\") {" << columnName << " = " << SQLITEtoCPP[type] << ";}" << endl;

        // CREATE TABLE `virtual_aliases` (
        //   `id` int(11) NOT NULL auto_increment,
        //   `domain_id` int(11) NOT NULL,
        //   `source` varchar(100) NOT NULL,
        //   `destination` varchar(100) NOT NULL,
        //   PRIMARY KEY (`id`),
        //   FOREIGN KEY (domain_id) REFERENCES virtual_domains(id) ON DELETE CASCADE
        // ) ENGINE=InnoDB DEFAULT CHARSET=utf8;
        columnCount++;
    }

    // Post Loop Constst    ructors
{'fraction_non_alphanumeric': 0.16807299843014128, 'fraction_numerical': 0.004905808477237049, 'mean_word_length': 2.7241505297771282, 'pattern_counts': {'":': 0, '<': 242, '<?xml version=': 0, '>': 48, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '100463', 'n_tokens_mistral': 3011, 'n_tokens_neox': 2885, 'n_words': 850}