@@ -57,9 +57,6 @@ func DropTable(command string) {
5757
5858func InsertInto (command string ) {
5959
60- //create table table (column1, column2, column3)
61- //ex: insert into table (column1, column2, column3) values (value1, value2, value3)
62-
6360 table := strings .Split (command , " " )[2 ]
6461
6562 if _ , err :=
@@ -68,7 +65,6 @@ func InsertInto(command string) {
6865 return
6966 }
7067
71- //escrever os values
7268 values := strings .Split (command , "values" )[1 ]
7369 values = strings .Split (values , "(" )[1 ]
7470 values = strings .Split (values , ")" )[0 ]
@@ -90,4 +86,40 @@ func InsertInto(command string) {
9086 }
9187
9288 fmt .Println ("Registro inserido com sucesso" )
93- }
89+ }
90+
91+ func SelectFrom (command string ) {
92+
93+ table := strings .Split (command , " " )[3 ]
94+
95+ if _ , err := os .Stat ("data/" + table + ".csv" ); os .IsNotExist (err ) {
96+ fmt .Println ("Tabela não existe" )
97+ return
98+ }
99+
100+ file , err := os .Open ("data/" + table + ".csv" )
101+ if err != nil {
102+ fmt .Println ("Erro ao abrir arquivo" )
103+ return
104+ }
105+
106+ defer file .Close ()
107+
108+ fmt .Println ("Tabela: " + table )
109+ fmt .Println ("" )
110+ var columns string
111+ fmt .Fscanf (file , "%s\n " , & columns )
112+ columns = strings .Replace (columns , ";" , " | " , - 1 )
113+ fmt .Println (columns )
114+
115+ var line string
116+ for {
117+ _ , err := fmt .Fscanf (file , "%s\n " , & line )
118+ if err != nil {
119+ break
120+ }
121+ line = strings .Replace (line , ";" , " | " , - 1 )
122+ fmt .Println (line )
123+ }
124+ }
125+
0 commit comments