Page 1 of 1

Sqlquery: create new table in main csdb

Posted: July 2nd, 2018, 2:04 am
by htuser
Dear Cspro developer team,
I would like to know if it's possible for users to create new table in Csdb using sqlquery. In this event, can we use writecase function to write data in this table?
Now, for each external dictionary, we're obliged to have an external Csdb file... using sqlquery to create new table in Csdb will eliminate the need for severals Csdb files...

Thanks in advance for your support!

Re: Sqlquery: create new table in main csdb

Posted: July 2nd, 2018, 7:40 am
by Gregory Martin
You can execute any valid SQLite statement using the SqlQuery function, so you could do something like "CREATE TABLE..." You won't be able to use WriteCase with this file though, as that only works with .csdb files described by CSPro dictionaries.

At one point we thought about allowing the data for multiple dictionaries to be stored in a single .csdb file but we decided against that. That is the approach that you really would have wanted.

Re: Sqlquery: create new table in main csdb

Posted: July 2nd, 2018, 10:28 am
by htuser
Hi Greg,
Thanks for your response!

Unfortunately :oops: , we'll continue to have multiples csdb files ... But, good news if we can create new table in any csdb file.
Right now, i'll try to create a new table and use insert into to transfer some items to this table.
Since sqlquery can't return string value, i'm still very limited now...

Hopefully :D , you informed that will change in the future with a sqlquery able to query string, items, records!

Best Regards,

Re: Sqlquery: create new table in main csdb

Posted: July 2nd, 2018, 10:38 am
by josh
Do this at your own risk. We reserve the right to completely change the format of the csdb file in future releases so there is no guarantee that code that you write to manipulate a csdb file using sql will work in future versions of cspro.

Re: Sqlquery: create new table in main csdb

Posted: July 2nd, 2018, 11:36 am
by Gregory Martin
SqlQuery can return a string value. See the example in the help: "Example - Query on CSPro DB File, Storing Results in List."

You can get the string value returned as the single and only element of the string list.

Re: Sqlquery: create new table in main csdb

Posted: July 2nd, 2018, 11:43 am
by htuser
Sorry Greg,
I misinterpret your sentence: "95% of the time with SqlQuery, you will want a numeric result, which is why it was designed to return a number."

@ Josh, Do you think it's a better idea to create the new table in the paradata log file?

Best!

Re: Sqlquery: create new table in main csdb

Posted: July 3rd, 2018, 11:29 am
by josh
I think it is a better idea to create the new in a separate file that is not a cspro file.

Re: Sqlquery: create new table in main csdb

Posted: July 4th, 2018, 6:16 pm
by htuser
Hi Josh,
Having a sqlquery able to extract items, record will cancel the need of creating new table. insert into etc.
Thanks to Greg and the whole Cspro Developer Team, the best existing small team, but smart team, who're implementing this.
In the meantime, what's happen with this code:

Code: Select all

string sqlReq =	maketext ("INSERT INTO identifiantquestionnaire (codetablet, codeutilisateur, numeroquestionnaire)VALUES (%v, %v, %v)",noTablet(),CODE_OPERATEUR,IQ_1_NUMERO_DU_QUESTIONNAIRF); ?
[/i]
Thanks a lot for your incredible support!