Skip to content

Commit

Permalink
Read students checked (#33)
Browse files Browse the repository at this point in the history
* Cleaning the code

* Read checked
  • Loading branch information
heyimnowi committed May 16, 2016
1 parent 36011de commit b7e6cee
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 23 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

*.bin
*.o
*.db
*.db
*.txt
5 changes: 2 additions & 3 deletions Api/namedPipe/namedPipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
#include <signal.h>
#include "../../Database/databaseapi.h"

static const char * serverMsg[7] = {
static const char * serverMsg[8] = {
"Estudiante agregado con exito!",
"El estudiante ya existe!",
"Estudiante modificado con exito!",
"Estudiante eliminado con exito!",
"Tabla creada con exito!",
"Tabla eliminada con exito!",
"Leyendo data...",
"Error en la base de datos!"
};

Expand Down Expand Up @@ -146,8 +147,6 @@ int requestServer(Connection * connection, int action, int dataSize, void * data
return responseFd[0];
}



Request * createRequest(int action, int fd, int dataSize, void * data){
Connection * connection = createConnection(fd);
connection -> dataSize = dataSize;
Expand Down
6 changes: 0 additions & 6 deletions Api/namedPipe/namedPipe.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef _NAMED_PIPE_H_
#define _NAMED_PIPE_H_

// From http://stackoverflow.com/questions/2784500/how-to-send-a-simple-string-between-two-programs-using-pipes
#include <stdio.h>
#include <string.h>
#include <fcntl.h>
Expand All @@ -12,14 +11,9 @@
#include "../commons.h"

#define NOT_FOUND_ERR 0

#define REQUEST_QUEUE "giladita"
#define SQL_QUEUE "bandadegilada"

#define BLOCK 1024

//the client should use this function to start a request
//request is initialized and sent to the server
Request * createRequest(int action, int fd, int dataSize, void * data);

Connection * createConnection(int fd);
Expand Down
17 changes: 9 additions & 8 deletions Api/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@
#define LISTEN_BACKLOG 50
#define MAX_CONNECTIONS 100


static const char * serverMsg[5] = {
"Estudiante agregado con exito ",
"El estudiante ya existe ",
"Estudiante modificado con exito ",
"Estudiante eliminado con exito ",
"Error en la base de datos "

static const char * serverMsg[8] = {
"Estudiante agregado con exito!",
"El estudiante ya existe!",
"Estudiante modificado con exito!",
"Estudiante eliminado con exito!",
"Tabla creada con exito!",
"Tabla eliminada con exito!",
"Leyendo data...",
"Error en la base de datos!"
};

Connection * openConnection(){
Expand Down
3 changes: 3 additions & 0 deletions Client/clientapi.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,20 @@ void apiUpdateStudent (char * currentName, char * newName, char * average) {
void apiDropTable() {
Connection *connection = malloc(sizeof(Connection));
requestServer(connection, DROP_TABLE , 0, NULL);
getResponse(connection);
}

void apiCreateTable() {
Connection *connection = malloc(sizeof(Connection));
requestServer(connection, CREATE_TABLE , 0, NULL);
getResponse(connection);
getResponse(connection);
}

void apiReadStudents() {
Connection *connection = malloc(sizeof(Connection));
requestServer(connection, READ_STUDENTS, 0, NULL);
getResponse(connection);
printStudents();
}

Expand Down
3 changes: 3 additions & 0 deletions Client/dababaseExport.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
Nowilamascapa 9.0
noelia 9.0
Belen 5.0
Nowinowi 9.0
Lopez 9.0
3 changes: 2 additions & 1 deletion Database/database.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ void processRequestDatabase (Request * request) {
break;

case READ_STUDENTS:
DbReadStudents();
state = DbReadStudents();
writeResponse(request, state);
break;

case DROP_TABLE:
Expand Down
5 changes: 1 addition & 4 deletions Database/databaseapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@
#define NO_TABLE 404
#define USER_EXISTS 19
#define NO_SESSION NULL
#define COMMA ","
#define LAST_P ");"
#define SEMILCOLON ";"
#define APOSTROPHE "'"
#define SQL_SELECT_ALL "select * from Students;"
#define USER_EXISTS_ERROR_MESSAGE "That user is already registered"
#define MISSING_TABLE 1
Expand All @@ -29,6 +25,7 @@ typedef enum { ADD_STUDENT_SUCCESS = 0,
DELETE_STUDENT_SUCCESS,
CREATE_TABLE_SUCCESS,
DROP_TABLE_SUCCESS,
READ_STUDENT_SUCESS,
DATABASE_ERROR,
} sqlState;

Expand Down

0 comments on commit b7e6cee

Please sign in to comment.