diff --git a/basicModels.go b/basicModels.go index 8675e18..2d09a9a 100644 --- a/basicModels.go +++ b/basicModels.go @@ -10,7 +10,7 @@ type patient struct { Name string Surname string BirthDate time.Time - PatientState sql.NullString + PatientState nullString PatientSex sex PatientEmail string } @@ -35,24 +35,24 @@ type doctor struct { type operation struct { OperationID int64 Name string - averageTime NullTime - operationType operationTypes - cost uint8 - refoundation int64 + AverageTime string + OperationType operationTypes + Cost float32 + Refoundation int64 } type room struct { - RoomNumber int - NumberOfBeds int - IncrasedCare bool + RoomNumber int + NumberOfBeds int + IncreasedCare bool } type admission struct { - AdmissionID string + AdmissionID int64 AdmissionDate time.Time EndDate NullTime - PatientPesel sql.NullString - DiagnosisSymbol sql.NullString + PatientPesel nullString + DiagnosisSymbol nullString MainDoctor int64 PlanedOperation int64 RoomNumber int64 diff --git a/databaseConnection.go b/databaseConnection.go index 8d0213f..8461abb 100644 --- a/databaseConnection.go +++ b/databaseConnection.go @@ -10,7 +10,7 @@ import ( _ "github.com/denisenkom/go-mssqldb" ) -var connectionString = "server=192.168.1.3;Port=1433;database=DB_s439397;trusted_connection=yes;encrypt=disable" +var connectionString = "server=192.168.1.2;Port=1433;database=DB_s439397;trusted_connection=yes;encrypt=disable" var db *sql.DB var err error @@ -32,11 +32,11 @@ func testConnection() { type iHasValue interface{} type values []iHasValue -func readDatabase(tableName string) (iDatabaseModels, error) { +// ODCZYT Z BAZY DANYCH BEZ SORTOWANIA +func readDatabase(command string, tableName string) (iDatabaseModels, error) { ctx := context.Background() checkIsDatabaseAlive() - tsql := "SELECT * FROM " + tableName - rows, _ := db.QueryContext(ctx, tsql) + rows, _ := db.QueryContext(ctx, command) defer rows.Close() var models iDatabaseModels models = nil @@ -66,20 +66,35 @@ func updateRecord(tableName string, primaryKey string, primaryKeyName string, fieldToUpdate string, valueToInsert string) string { ctx := context.Background() checkIsDatabaseAlive() - tsql := "UPDATE " + tableName + " SET " + fieldToUpdate + " = '" + valueToInsert + - "' WHERE " + primaryKeyName + " = '" + primaryKey + "'" - result, _ := db.ExecContext(ctx, tsql) - toReturn, _ := result.RowsAffected() - return (strconv.FormatInt(toReturn, 10)) + if valueToInsert == "null" { + valueToInsert = "NULL" + } else { + valueToInsert = "'" + valueToInsert + "'" + } + tsql := "UPDATE " + tableName + " SET " + fieldToUpdate + " = " + valueToInsert + + " WHERE " + primaryKeyName + " = '" + primaryKey + "'" + result, er := db.ExecContext(ctx, tsql) + if er == nil { + toReturn, _ := result.RowsAffected() + return (strconv.FormatInt(toReturn, 10)) + } + return "ERROR" } func insertRecord(command string) string { ctx := context.Background() checkIsDatabaseAlive() - /*tsql := "INSERT " + tableName + " VALUES '" + primaryKey + "'" - for i := 0; i