Table exists?

Post Reply
bhiggins
Posts: 11
Joined: Wed Nov 13, 2002 8:10 pm

Table exists?

Post by bhiggins »

I'm very new to Vortex, so please bear with me. I've searched for quite a while before asking this.

I've got an application in which I want to create a table on the fly, with the name taken from a form. However, I want to check if a table by that name already exists in the database, and if so inform the user of that.

So...Is there some sort of tableExists function? Or am I way off base?

Thanks,
Bob
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Table exists?

Post by mark »

<sql novars "select * from SYSTABLES where NAME=$tablename"></sql>
<if $loop ne 0>
Table exists
<else>
Table does not exist
</if>

You should do some filtering of the user's input so you don't get stupid table names. Maybe something like
<sandr "[^\alpha]+" "" $tablename><$tablename=$ret>
bhiggins
Posts: 11
Joined: Wed Nov 13, 2002 8:10 pm

Table exists?

Post by bhiggins »

Of course. Seems clear now, but I was all over the place. This is exactly what I needed. And your suggestion for how to filter the user input is a good one.

Thanks so much,
Bob
amitic
Posts: 14
Joined: Fri Jul 02, 2010 10:57 pm

Table exists?

Post by amitic »

Is it possible to check if a RAM table already exists?
I would like to emulate 'drop table if exists'.

I can still do:
<vxcp putmsg ... 0>
and then a precautionary 'drop table' and putmsg restore, but it would be nice to have a 'cleaner' approach.
User avatar
mark
Site Admin
Posts: 5519
Joined: Tue Apr 25, 2000 6:56 pm

Table exists?

Post by mark »

I don't think so. But since a ram table only exists for the duration of your script you can just set a variable when you create it so you know if it exists and when.
amitic
Posts: 14
Joined: Fri Jul 02, 2010 10:57 pm

Table exists?

Post by amitic »

The script actually creates multiple ram tables with names determined at runtime, but i guess i could have an xtree with table names added when a table is created and removed when it is dropped.
Thank You
Post Reply