fix insert err return & timestamp formatting

This commit is contained in:
ycc 2022-05-19 10:49:19 +02:00
parent df398dab1a
commit d99db63940
9 changed files with 6 additions and 186 deletions

View File

@ -3,4 +3,3 @@ dbentity
id : integer id : integer
parent_id : bigint parent_id : bigint
type : varchar(255) type : varchar(255)
}

View File

@ -2,4 +2,3 @@ dbrole
description : text description : text
id : integer id : integer
name : varchar name : varchar
}

View File

@ -3,4 +3,3 @@ dbtableaccess
id : integer id : integer
tableaccess : varchar(255) tableaccess : varchar(255)
userrolerestrictions : varchar(255) userrolerestrictions : varchar(255)
}

View File

@ -2,4 +2,3 @@ dbuser
id : integer id : integer
login : varchar(255)|comment login : varchar(255)|comment
password : varchar(255) password : varchar(255)
}

View File

@ -5,4 +5,3 @@ dbuserrole
enddate : timestamp without time zone enddate : timestamp without time zone
id : integer id : integer
startdate : timestamp without time zone startdate : timestamp without time zone
}

View File

@ -2,4 +2,3 @@ testtype
detail : varchar(255) detail : varchar(255)
id : integer id : integer
name : varchar(255) name : varchar(255)
}

6
pg.go
View File

@ -329,8 +329,8 @@ func (t *TableInfo) Insert(record AssRow) (int, error) {
values += FormatForSQL(t.Columns[key], element) + "," values += FormatForSQL(t.Columns[key], element) + ","
} }
t.db.conn.QueryRow("INSERT INTO " + t.Name + "(" + removeLastChar(columns) + ") VALUES (" + removeLastChar(values) + ") RETURNING id").Scan(&id) err = t.db.conn.QueryRow("INSERT INTO " + t.Name + "(" + removeLastChar(columns) + ") VALUES (" + removeLastChar(values) + ") RETURNING id").Scan(&id)
return id, nil return id, err
} }
func (t *TableInfo) Update(record AssRow) error { 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 { if !strings.Contains(datatype, "char") && len(strval) == 0 {
return "NULL" 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(pq.QuoteLiteral(strval))
} }
return fmt.Sprint(strval) return fmt.Sprint(strval)

View File

@ -1,13 +1,4 @@
[ [
{
"name": "computer",
"columns": {
"description": "varchar(1000)",
"id": "integer",
"name": "varchar(255)|comment",
"os": "varchar(255)"
}
},
{ {
"name": "dbentity", "name": "dbentity",
"columns": { "columns": {
@ -53,61 +44,6 @@
"startdate": "timestamp without time zone" "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", "name": "testtype",
"columns": { "columns": {
@ -115,42 +51,5 @@
"id": "integer", "id": "integer",
"name": "varchar(255)" "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"
}
} }
] ]

View File

@ -1,13 +1,6 @@
@startuml @startuml
entity computer {
description : varchar(1000)
id : integer
name : varchar(255)|comment
os : varchar(255)
}
entity dbentity { entity dbentity {
description : text description : text
id : integer id : integer
@ -43,90 +36,24 @@ entity dbuserrole {
startdate : timestamp without time zone 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 { entity testtype {
detail : varchar(255) detail : varchar(255)
id : integer id : integer
name : varchar(255) 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 dbentity ||..|| parent
dbtableaccess ||..|| dbrole dbtableaccess ||..|| dbrole
dbuserrole ||..|| dbuser
dbuserrole ||..|| dbentity dbuserrole ||..|| dbentity
dbuserrole ||..|| dbrole dbuserrole ||..|| dbrole
dbuserrole ||..|| dbuser
software_computer ||..|| computer
software_computer ||..|| software
test ||..|| testtype
timetracking ||..|| entity
timetracking ||..|| person
timetracking ||..|| entity
@enduml @enduml