Picture of Rico 1837
Registered 10 years 245 days
Rico 1837 Wednesday, 20 October 2021, 03:50 PM
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



Picture of Anton
Registered 5 years 116 days
Anton Tuesday, 30 November 2021, 04:55 PM
Re: [JS] use SQL Statements / database config.json
Hi Rico,

I like to do the same thing as you described.

If i understand the doc correctly at:
https://sdk.innovaphone.com/13r2/doc/appgeneric.htm#client-SqlInsert

We should be able to handle the database via websocket calls, but I cannot get it to work.

Have you got some update on this problem, or maybe someone else can help? =)

Thanks
Anton
Picture of Rico 1837
Registered 10 years 245 days
Rico 1837 Tuesday, 30 November 2021, 06:52 PM
1 of 1 users consider this post helpful
Re: [JS] use SQL Statements / database config.json
there is a config.json file below with a declaration of a table and defined statements to add/change/delete/list the table rows.
with the statements defined you can use the api calls as described at the docs you linked.
like
{ "mt": "SqlExec", "statement": "schuhschrank_list" }
 or 
{ "mt": "SqlInsert", "statement": "schuhschrank_add" "args": { "name": "small schuschrank", "width": 200, "height": 100, "auflager": true } } 
hope that helps

Rico
schuhschrank_config.json
← You can define your color theme preference here