~aritra1911/cylinder

c3f7b1e841482a7e3ae68ea3c77e0a9162c2d5f3 — Aritra Sarkar 3 years ago 19d7575
Upgrade C remove() to C++17 remove()
4 files changed, 17 insertions(+), 27 deletions(-)

M Makefile
M schema.cpp
M schema.hpp
M sqlparser.cpp
M Makefile => Makefile +1 -1
@@ 1,4 1,4 @@
CXXFLAGS = -Wall -Wextra -pedantic -std=c++11
CXXFLAGS = -Wall -Wextra -pedantic -std=c++17
LIBS =
SRC = main.cpp schema.cpp sqlparser.cpp field_type.cpp
OBJ = main.o schema.o sqlparser.o field_type.o

M schema.cpp => schema.cpp +5 -19
@@ 1,7 1,5 @@
#include <iostream>
#include <cstdio>
#include <cerrno>
#include <cstring>
#include <filesystem>
#include "schema.hpp"
#include "field_type.hpp"



@@ 48,25 46,13 @@ int Schema::create(const std::string& name) {
    return 0;
}

int Schema::drop(const std::string& name) {
void Schema::drop( const std::string& name ) {
    /* Is able to delete file for any schema given a name */

    /* Try to open schema file and if we're not successful, then it doesn't exist. */
    std::ifstream f(SCHEMA_FILE(name));
    if (!f.is_open()) {
        std::cerr << "Schema doesn't exist\n";
        return -1;
    }
    f.close();  /* It opened, so close it */

    errno = 0;  /* Make sure `errno' is reset */
    if (std::remove(SCHEMA_FILE(name).c_str()) == -1) {
        std::cerr << SCHEMA_FILE(name) << ": " << std::strerror(errno);
        errno = 0;
        return -1;
    }
    std::filesystem::path p = SCHEMA_FILE( name );

    return 0;
    if ( !std::filesystem::remove( p ) )
        throw DoesntExistException();
}

void Schema::create_table(const std::string& name, AbstractField** fields, const size_t& num_fields) {

M schema.hpp => schema.hpp +1 -1
@@ 18,7 18,7 @@ class Schema {
    Schema(const std::string&);
    std::string get_name(void);
    static int create(const std::string&);
    static int drop(const std::string&);
    static void drop( const std::string& );
    void create_table(const std::string&, AbstractField**, const size_t&);
    ~Schema(void);
};

M sqlparser.cpp => sqlparser.cpp +10 -6
@@ 187,17 187,21 @@ void SQL::execute(Schema*& schema) {  /* TODO: Should `schema' be mutable? */
                    /* If the parse() works correctly, and provided no break statements were missed above, this case
                     * should never be reached. */
                    std::cerr << "You shouldn't be seeing this!\n";

            }
            break;

        case DROP:
            switch (substatement) {
            switch ( substatement ) {
                case SCHEMA:
                    if (Schema::drop(name) == -1)
                        std::cerr << "Couldn't drop schema!\n";
                    else
                        std::cout << "Schema dropped!\n";
                    try {
                        Schema::drop( name );

                    } catch ( Schema::DoesntExistException ) {
                        std::cerr << "Schema doesn't exist!\n";
                        break;
                    }

                    std::cout << "Schema dropped!\n";
                    break;

                default: