Exemple #1
0
 def createTable(self, tableName, numberColumns):
     salida = self.Buscar(tableName)
     if salida[0]:
         return 3
     else:
         try:
             if re.search(table_name_pattern, tableName):
                 self.list_table.append(tableName)
                 temp = Tabla.Tabla(tableName, numberColumns)
                 serealizar.commit(temp, tableName, self.main_path)
                 return 0
             else:
                 return 1
         except:
             return 1
Exemple #2
0
def loadCSV(file: str, database: str, table: str) -> int:

    try:
        archivo = open(file)

    except:
        return 1

    temp = storage.Buscar(database)

    if temp:

        b = temp.Buscar(table)
        nombre = temp.list_table[b[1]]

        tabla = serealizar.rollback(nombre, main_path + "\\" + database)

        if b[0]:

            temp_registros = archivo.readlines()

            registros = []

            for registro in temp_registros:
                registros.append(registro.replace("\n", "").split(","))

            for registro in registros:

                valor = tabla.insertar(registro)

                if valor:
                    serealizar.commit(tabla, table,
                                      main_path + "\\" + database)
                    return valor

            else:
                serealizar.commit(tabla, table, main_path + "\\" + database)
                return 0

        else:
            return 3

    else:
        return 2
Exemple #3
0
def truncate(database: str, table: str) -> int:

    temp = storage.Buscar(database)

    if temp:

        b = temp.Buscar(table)
        nombre = temp.list_table[b[1]]

        tabla = serealizar.rollback(nombre, main_path + "\\" + database)

        if b[0]:
            var = tabla.truncate()
            serealizar.commit(tabla, table, main_path + "\\" + database)

            return var

        else:
            return 3

    else:
        return 2
Exemple #4
0
def update(database: str, table: str, register: dict, columns: list) -> int:

    temp = storage.Buscar(database)

    if temp:

        b = temp.Buscar(table)
        nombre = temp.list_table[b[1]]

        tabla = serealizar.rollback(nombre, main_path + "\\" + database)

        if b[0]:
            var = tabla.update(columns, register)
            serealizar.commit(tabla, table, main_path + "\\" + database)

            return var

        else:
            return 3

    else:
        return 2
Exemple #5
0
 def Guardar(self):
     serealizar.commit(self.tabla_actual, self.tabla_actual.nombre,
                       self.main_path)