From d99db639408a153c6be39f3fffba38bb51add1e1 Mon Sep 17 00:00:00 2001 From: ycc Date: Thu, 19 May 2022 10:49:19 +0200 Subject: [PATCH] fix insert err return & timestamp formatting --- gen/dbentity.html | 1 - gen/dbrole.html | 1 - gen/dbtableaccess.html | 1 - gen/dbuser.html | 1 - gen/dbuserrole.html | 1 - gen/testtype.html | 1 - pg.go | 6 +-- schema.json | 103 +---------------------------------------- schema.puml | 77 +----------------------------- 9 files changed, 6 insertions(+), 186 deletions(-) diff --git a/gen/dbentity.html b/gen/dbentity.html index 3ff966c..c40288c 100644 --- a/gen/dbentity.html +++ b/gen/dbentity.html @@ -3,4 +3,3 @@ dbentity id : integer parent_id : bigint type : varchar(255) -} \ No newline at end of file diff --git a/gen/dbrole.html b/gen/dbrole.html index 11df578..9837aeb 100644 --- a/gen/dbrole.html +++ b/gen/dbrole.html @@ -2,4 +2,3 @@ dbrole description : text id : integer name : varchar -} \ No newline at end of file diff --git a/gen/dbtableaccess.html b/gen/dbtableaccess.html index d0acb94..1754655 100644 --- a/gen/dbtableaccess.html +++ b/gen/dbtableaccess.html @@ -3,4 +3,3 @@ dbtableaccess id : integer tableaccess : varchar(255) userrolerestrictions : varchar(255) -} \ No newline at end of file diff --git a/gen/dbuser.html b/gen/dbuser.html index 944e720..def379c 100644 --- a/gen/dbuser.html +++ b/gen/dbuser.html @@ -2,4 +2,3 @@ dbuser id : integer login : varchar(255)|comment password : varchar(255) -} \ No newline at end of file diff --git a/gen/dbuserrole.html b/gen/dbuserrole.html index b962294..d99da8a 100644 --- a/gen/dbuserrole.html +++ b/gen/dbuserrole.html @@ -5,4 +5,3 @@ dbuserrole enddate : timestamp without time zone id : integer startdate : timestamp without time zone -} \ No newline at end of file diff --git a/gen/testtype.html b/gen/testtype.html index 1433f48..3d41167 100644 --- a/gen/testtype.html +++ b/gen/testtype.html @@ -2,4 +2,3 @@ testtype detail : varchar(255) id : integer name : varchar(255) -} \ No newline at end of file diff --git a/pg.go b/pg.go index da402df..fa99502 100755 --- a/pg.go +++ b/pg.go @@ -329,8 +329,8 @@ func (t *TableInfo) Insert(record AssRow) (int, error) { values += FormatForSQL(t.Columns[key], element) + "," } - t.db.conn.QueryRow("INSERT INTO " + t.Name + "(" + removeLastChar(columns) + ") VALUES (" + removeLastChar(values) + ") RETURNING id").Scan(&id) - return id, nil + err = t.db.conn.QueryRow("INSERT INTO " + t.Name + "(" + removeLastChar(columns) + ") VALUES (" + removeLastChar(values) + ") RETURNING id").Scan(&id) + return id, err } func (t *TableInfo) Update(record AssRow) error { @@ -523,7 +523,7 @@ func FormatForSQL(datatype string, value interface{}) string { if !strings.Contains(datatype, "char") && len(strval) == 0 { return "NULL" } - if strings.Contains(datatype, "char") || strings.Contains(datatype, "date") { + if strings.Contains(datatype, "char") || strings.Contains(datatype, "date") || strings.Contains(datatype, "timestamp") { return fmt.Sprint(pq.QuoteLiteral(strval)) } return fmt.Sprint(strval) diff --git a/schema.json b/schema.json index 82c4f41..1e9666f 100644 --- a/schema.json +++ b/schema.json @@ -1,13 +1,4 @@ [ - { - "name": "computer", - "columns": { - "description": "varchar(1000)", - "id": "integer", - "name": "varchar(255)|comment", - "os": "varchar(255)" - } - }, { "name": "dbentity", "columns": { @@ -53,61 +44,6 @@ "startdate": "timestamp without time zone" } }, - { - "name": "entity", - "columns": { - "enddate": "date", - "id": "integer", - "name": "varchar(255)", - "startdate": "date", - "type": "varchar(255)" - } - }, - { - "name": "person", - "columns": { - "email": "varchar(255)", - "firstname": "varchar(255)", - "id": "integer", - "mobile": "varchar(255)", - "name": "varchar(255)" - } - }, - { - "name": "software", - "columns": { - "company": "varchar(255)", - "description": "varchar(1000)", - "id": "integer", - "licenseend": "date", - "name": "varchar(255)|comment", - "support": "varchar(255)" - } - }, - { - "name": "software_computer", - "columns": { - "computer_id": "integer", - "id": "integer", - "software_id": "integer" - } - }, - { - "name": "test", - "columns": { - "description": "varchar(1000)", - "enddate": "timestamp without time zone", - "floatvalue": "double precision", - "id": "integer", - "intvalue": "integer", - "latitude": "double precision|map", - "longitude": "double precision|map", - "name": "varchar(255)|comment", - "price": "money", - "startdate": "timestamp without time zone", - "testtype_id": "integer" - } - }, { "name": "testtype", "columns": { @@ -115,42 +51,5 @@ "id": "integer", "name": "varchar(255)" } - }, - { - "name": "timetracking", - "columns": { - "afternoon_entity_id": "integer", - "comment": "varchar(255)", - "day": "date", - "id": "integer", - "morning_entity_id": "integer" - } - }, - { - "name": "surveyquestion", - "columns": { - "type": "integer", - "label": "varchar(1000)", - "responses": "varchar(1000)", - "id": "integer", - "votes": "integer" - } - }, - { - "name": "surveyresponse", - "columns": { - "surveyuser_id": "integer", - "surveyquestion_id": "varchar(255)", - "response": "varchar(1000)", - "id": "integer" - } - }, - { - "name": "surveyuser", - "columns": { - "voted": "bool", - "code": "varchar(255)", - "id": "integer" - } - } + } ] \ No newline at end of file diff --git a/schema.puml b/schema.puml index 2478a8a..d13053c 100644 --- a/schema.puml +++ b/schema.puml @@ -1,13 +1,6 @@ @startuml -entity computer { - description : varchar(1000) - id : integer - name : varchar(255)|comment - os : varchar(255) -} - entity dbentity { description : text id : integer @@ -43,90 +36,24 @@ entity dbuserrole { startdate : timestamp without time zone } -entity entity { - enddate : date - id : integer - name : varchar(255) - startdate : date - type : varchar(255) -} - -entity person { - email : varchar(255) - firstname : varchar(255) - id : integer - mobile : varchar(255) - name : varchar(255) -} - -entity software { - company : varchar(255) - description : varchar(1000) - id : integer - licenseend : date - name : varchar(255)|comment - support : varchar(255) -} - -entity software_computer { - computer_id : integer - id : integer - software_id : integer -} - -entity test { - description : varchar(1000) - enddate : timestamp without time zone - floatvalue : double precision - id : integer - intvalue : integer - latitude : double precision|map - longitude : double precision|map - name : varchar(255)|comment - price : money - startdate : timestamp without time zone - testtype_id : integer -} - entity testtype { detail : varchar(255) id : integer name : varchar(255) } -entity timetracking { - afternoon_entity_id : integer - comment : varchar(255) - day : date - id : integer - morning_entity_id : integer - person_id : integer -} - dbentity ||..|| parent dbtableaccess ||..|| dbrole +dbuserrole ||..|| dbuser + dbuserrole ||..|| dbentity dbuserrole ||..|| dbrole -dbuserrole ||..|| dbuser - -software_computer ||..|| computer - -software_computer ||..|| software - -test ||..|| testtype - -timetracking ||..|| entity - -timetracking ||..|| person - -timetracking ||..|| entity - @enduml