1 of 1 users consider this post helpful
[JS] use SQL Statements / database config.json
Ahoi,
Im trying to use sql statements stated at
https://sdk.innovaphone.com/13r2/doc/appgeneric.htm#client
https://sdk.innovaphone.com/13r2/doc/appgeneric.htm#client-SqlInsert
I have a table definition like this:
"database": {
"init": [
{
"cmd": "table",
"name": "items",
"init": [
{
"cmd": "column",
"name": "id",
"type": "BIGSERIAL PRIMARY KEY NOT NULL"
},
{
"cmd": "column",
"name": "title",
"type": "VARCHAR(255) NOT NULL"
},
{
"cmd": "column",
"name": "published",
"type": "BOOLEAN NOT NULL"
}
]
},
{
"cmd": "statement",
"name": "item_add",
"mode": "owner", <---- ?
"query": "INSERT INTO items (title, published) VALUES (%s, %b)",
tried
"args": {
"title": "rtfm doesnt help",
"published": "true_or_false_is_the_question",
},
or
"args": {
"1": "title",
"2": "published",
},
or
"args": {
"title": 0,
"published": 1,
},
even
"args": [
"title",
"published"
],
"return": "retvalue"
}
{
"cmd": "statement",
"name": "item_add_hardcoded",
"mode": "owner", <----- ?
"query": "INSERT INTO items (title, published) VALUES ('this works fine', true)",
"return": "retvalue"
}
]
}
The statement 'item_add_hardcoded' works fine as expected.
{
mt: "SqlInsert",
statement: "item_add_hardcoded",
args: {
title: "new item",
published: true
}
}
I like to send websocket messages like this to create a new item:
{
mt: "SqlExec or SqlInsert",
statement: "item_add",
args: {
title: "new item",
published: true
}
}
But that only results in errors in the generic app/app-service:
10-20 12:12:14.849 AppWebsocket(001afd90)::AppWebsocketRecvResult {"mt":"SqlExec or SqlInsert","statement":"item_add","args":{"title":"new item","published":true},"src":6187133342500792}
10-20 12:12:14.849 GenericSession(1afd90)::AppWebsocketMessage(SqlExec)
10-20 12:12:14.849 SqlExec::SqlExec()
10-20 12:12:14.850 PostgreSQLDatabase(001836b8,0017edf8)::ExecSQL(PS) user:001749e4 flags:0 statement: INSERT INTO articles (title, published) VALUES (' <----- [SIC] it ends here, no copypaste error
10-20 12:12:14.853 PostgreSQLDatabase(001836b8,0017edf8)::LastCommandFailed (23502):ERROR: null value in column "title" violates not-null constraint
DETAIL: Failing row contains (59, null, null).
10-20 12:12:14.856 PostgreSQLDatabase(001836b8,001749e4)::DatabaseError error: DB_ERR_SQL_COMMAND_FAILED
How can i use parameters of websocket messages in querys with %s, %i replacements, whats wrong here?
And please give an example of the usage of this @domain, @sip or @dn vars in that sql querys.
thanks
Im trying to use sql statements stated at
https://sdk.innovaphone.com/13r2/doc/appgeneric.htm#client
https://sdk.innovaphone.com/13r2/doc/appgeneric.htm#client-SqlInsert
I have a table definition like this:
"database": {
"init": [
{
"cmd": "table",
"name": "items",
"init": [
{
"cmd": "column",
"name": "id",
"type": "BIGSERIAL PRIMARY KEY NOT NULL"
},
{
"cmd": "column",
"name": "title",
"type": "VARCHAR(255) NOT NULL"
},
{
"cmd": "column",
"name": "published",
"type": "BOOLEAN NOT NULL"
}
]
},
{
"cmd": "statement",
"name": "item_add",
"mode": "owner", <---- ?
"query": "INSERT INTO items (title, published) VALUES (%s, %b)",
tried
"args": {
"title": "rtfm doesnt help",
"published": "true_or_false_is_the_question",
},
or
"args": {
"1": "title",
"2": "published",
},
or
"args": {
"title": 0,
"published": 1,
},
even
"args": [
"title",
"published"
],
"return": "retvalue"
}
{
"cmd": "statement",
"name": "item_add_hardcoded",
"mode": "owner", <----- ?
"query": "INSERT INTO items (title, published) VALUES ('this works fine', true)",
"return": "retvalue"
}
]
}
The statement 'item_add_hardcoded' works fine as expected.
{
mt: "SqlInsert",
statement: "item_add_hardcoded",
args: {
title: "new item",
published: true
}
}
I like to send websocket messages like this to create a new item:
{
mt: "SqlExec or SqlInsert",
statement: "item_add",
args: {
title: "new item",
published: true
}
}
But that only results in errors in the generic app/app-service:
10-20 12:12:14.849 AppWebsocket(001afd90)::AppWebsocketRecvResult {"mt":"SqlExec or SqlInsert","statement":"item_add","args":{"title":"new item","published":true},"src":6187133342500792}
10-20 12:12:14.849 GenericSession(1afd90)::AppWebsocketMessage(SqlExec)
10-20 12:12:14.849 SqlExec::SqlExec()
10-20 12:12:14.850 PostgreSQLDatabase(001836b8,0017edf8)::ExecSQL(PS) user:001749e4 flags:0 statement: INSERT INTO articles (title, published) VALUES (' <----- [SIC] it ends here, no copypaste error
10-20 12:12:14.853 PostgreSQLDatabase(001836b8,0017edf8)::LastCommandFailed (23502):ERROR: null value in column "title" violates not-null constraint
DETAIL: Failing row contains (59, null, null).
10-20 12:12:14.856 PostgreSQLDatabase(001836b8,001749e4)::DatabaseError error: DB_ERR_SQL_COMMAND_FAILED
How can i use parameters of websocket messages in querys with %s, %i replacements, whats wrong here?
And please give an example of the usage of this @domain, @sip or @dn vars in that sql querys.
thanks