Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2627c3a

Browse files
Fixed more of the issues, including (issude #3) (PR #4)
2 parents 09447ff + e663bb9 commit 2627c3a

File tree

5 files changed

+64
-40
lines changed

5 files changed

+64
-40
lines changed

‎ConsoleSQL.py‎

Lines changed: 27 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import shutil
23
import errors
34

45

@@ -136,23 +137,16 @@ def write_in_file(database, file, *content):
136137
return f"Database \"{database}\" or File \"{file}\" not found!"
137138

138139

139-
def check_table_content(database, table, *border):
140+
def check_table_content(database, table, *args):
140141
'''
141142
Console command
142-
143-
without border: GET ALL TableName
144-
with border: GET 3 TableName # border equals 3, gets the first three lines
143+
GET ALL TableName
145144
'''
146145

147146
if os.path.exists(f"databases/{database}/tables/{table}.txt"):
148147
file = open(f"databases/{database}/tables/{table}.txt", "r")
149148

150-
if border:
151-
if type(border[0]) is int:
152-
if border[0] < len([line for line in file]):
153-
return [line for line in file[3:border[0]+4]]
154-
155-
return [line for line in file[3:]]
149+
return [line for line in file][2:]
156150

157151
print("Table not found!")
158152
return []
@@ -161,18 +155,11 @@ def check_table_content(database, table, *border):
161155
def check_file_content(database, file_name, *border):
162156
'''
163157
Console command
164-
165-
without border: GET FILE FileName
166-
with border: GET FILE FileName 3 # border equals 3, gets the first three lines
158+
GET FILE FileName
167159
'''
168160

169161
if os.path.exists(f"databases/{database}/files/{file_name}.txt"):
170-
file = open(f"databases/{database}/tables/{file_name}.txt", "r")
171-
172-
if border:
173-
if type(border[0]) is int:
174-
if border[0] < len([line for line in file]):
175-
return [line for line in file[:border[0] + 1]]
162+
file = open(f"databases/{database}/files/{file_name}.txt", "r")
176163

177164
return [line for line in file]
178165

@@ -195,7 +182,7 @@ def drop_database(*databases):
195182

196183
for db in databases:
197184
if os.path.exists(f"databases/{db}/"):
198-
os.remove(f"databases/{db}/")
185+
shutil.rmtree(f"databases/{db}/")
199186

200187
return "Database/s dropped!"
201188

@@ -247,6 +234,21 @@ def code_saver(user_input, code_file, new_line):
247234

248235

249236
def run_program():
237+
while True:
238+
db = input("create or use database: ")
239+
240+
if db == 'create':
241+
create_db = input("database name: ")
242+
create_database(create_db)
243+
d = use_database(create_db)
244+
break
245+
246+
elif db == "use":
247+
d = use_database(input("database name: "))[-1]
248+
break
249+
250+
database = d
251+
250252
while True:
251253
file = input("Create or choose file where to save the code from your console experience:\n")
252254

@@ -327,7 +329,7 @@ def run_program():
327329
code_saver(item, file, '\n\n\n')
328330
print(add_content_to_table(database, table, *lst_values))
329331

330-
elif operation[:-1] == ["create" "file"]:
332+
elif operation[:-1] == ["create", "file"]:
331333
print(create_file(database, operation[-1]))
332334

333335
elif operation[:-1] == ["write", "in"]:
@@ -344,22 +346,16 @@ def run_program():
344346
content.append(text)
345347

346348
if operation[-1][-1] == ':':
347-
print(write_in_file(database, operation[-1][:-1], content))
349+
print(write_in_file(database, operation[-1][:-1], *content))
348350

349351
else:
350-
print(write_in_file(database, operation[-1], content))
352+
print(write_in_file(database, operation[-1], *content))
351353

352-
code_saver(content, file, '\n\n\n')
354+
code_saver(content[-1], file, '\n\n\n')
353355

354356
elif operation[0] == "get" and operation[1] == "all":
355357

356-
lines = check_table_content(database, operation[1])
357-
print()
358-
[print(line) for line in lines]
359-
360-
elif operation[0] == "get" and operation[1].isdigit():
361-
362-
lines = check_table_content(database, operation[-1], int(operation[1]))
358+
lines = check_table_content(database, operation[-1])
363359
print()
364360
[print(line) for line in lines]
365361

@@ -369,12 +365,6 @@ def run_program():
369365
print()
370366
[print(line) for line in lines]
371367

372-
elif operation[:-2] == ["get", "file"]:
373-
374-
lines = check_file_content(database, operation[-2], int(operation[-1]))
375-
print()
376-
[print(line) for line in lines]
377-
378368
elif operation[:-1] == ["drop", "db"] or operation[:-1] == ["drop", "database"] or operation[:2] == \
379369
["drop", "dbs"] or operation[:2] == ["drop", "databases"]:
380370

@@ -388,6 +378,3 @@ def run_program():
388378
print(delete_file(database, *operation[2:]))
389379

390380
code_saver('\n// everything bellow is made on new run.', file, '\n')
391-
392-
393-
run_program()

‎databases/mydb/files/myfile.txt‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Everything is alright.
2+
I love to write in files!
3+
The End of This;;;

‎databases/mydb/tables/mytable.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{'id': 'int', 'name': 'str', 'age': 'int'}
22

33
{"'id'": 1, "'name'": 'gosheto', "'age'": 17}
4+
{"'id'": 5, "'name'": 'dimko', "'age'": 17}

‎main.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import ConsoleSQL
2+
3+
if __name__ == '__main__':
4+
ConsoleSQL.run_program()

‎src/mydb.txt‎

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,32 @@ ADD mytable VALUES (
99
);
1010

1111
// everything bellow is made on new run.
12+
USE DATABASE mydb
13+
CREATE FILE myfile
14+
15+
// everything bellow is made on new run.
16+
USE DATABASE mydb
17+
WRITE IN myfile:
18+
Everything is alright.
19+
I love to write in files!
20+
The End of This;;;
21+
22+
23+
GET ALL mytable
24+
25+
ADD mytable VALUES (
26+
(5, dimko, 17)
27+
);
28+
29+
30+
GET FILE myfile
31+
CREATE DATABASE DELETEABLE
32+
CREATE TABLE deletble(id: int)
33+
CREATE FILE file
34+
DROP DB deleteable
35+
DROP TABLE file
36+
DROP TABLE deletble
37+
DEL FILE file
38+
END
39+
40+
// everything bellow is made on new run.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /