Create DB tables dynamically

Questions and answers regarding general SQL and backend databases

Create DB tables dynamically

Postby sergei.sheinin » Tue May 13, 2014 12:44 pm

I need to create database tables in a DB dynamically.


There is a database table containing metadata of new tables. For example:

    TableA: col_1 varchar(10), col_2 int
    TableB: col_3 text, col_4 bytea


A Servoy form will list all tables, let a user pick which ones to create, provide a drop-down of databases to choose in which the tables will be created.


And then comes the hard part (I am new to Servoy).

I can generate SQL "CREATE TABLE" DDL statement but don't think it's the best solution because
a) DDL is database platform-specific and b) must synchronize structure of updated database with servoy.


After looking through manuals I found these functions:


Code: Select all
var server = plugins.maintenance.getServer('test_db');
var table = server.createNewTable('new_table');
var pk = table.createNewColumn('new_table_id', JSColumn.INTEGER, 0);
...

which look good but work only in maintenance mode. I understand that it implies that it can not run from Web client.


What may you suggest?

Running DDL statements directly on DB then synchronising it with Servoy (and have to implement separate syntax specs for each platform)?
Use "createNewTable" from Web Client, if so, how?
Another solution?


Thanks
Sergei Sheinin
JavaScript, RDBMS
http://js2dx.com
sergei.sheinin
 
Posts: 79
Joined: Wed May 07, 2014 3:22 pm

Return to SQL Databases

Who is online

Users browsing this forum: No registered users and 11 guests

cron