_Ralph_
12th January 2007, 18:21
Hi all :)

Could you explain me how to check if a table exists in a respective company??

I try to use the dll

ttadvtablecomp
table.in.compnr(string table, long company)

but its always returns 0, even for unknow tables.:(

Could you give me some examples?:D

regards

ralph

mark_h
12th January 2007, 20:55
Well I do not know about that function, but what I did in one program was to use dynamic sql to check fields and count rows in a table. I can not remember if it was the parse or the fetch that returned an error when the table was not allocated. You can play with this and just a thought. There is probably something easier, but this could hold you over until a real expert shows up. Too many libraries for me to know what is where.

function domain tcbool field_is_used()
{
string sql(120)
long sql_id
domain tcbool found

| First check to make sure table has not expired
select ttadv420.expi
from ttadv420
where ttadv420._index1 = {:ttadv422.cpac, :ttadv422.cmod, :ttadv422.flno,
:ttadv422.vers, :ttadv422.rele, :ttadv422.cust}
and ttadv420._compnr = 0
as set with 1 rows
selectdo
selectempty
| Not found in here the return false. Table not used
return(false)
endselect
if ttadv420.expi = ttyeno.yes then
return(false)
endif

| Errors should now return false - so unallocated tables will be skipped.
error.bypass = 1
found = false
sql = "select " & table.field & " from " & table.name
sql = sql & " where " & table.field & " <> """" as set with 1 rows"
sql_id = sql.parse(sql)
sql.exec(sql_id)
while true
on case sql.fetch(sql_id)
case eendfile:
found = false
break
case 0:
found = true
break
default:
found = false
endcase
break
endwhile
error.bypass = 0
sql.break(sql_id)
sql.close(sql_id)
return(found)
}

|******************************************************************************
| Use dynamic sql to count rows on a table.
|******************************************************************************
function double count_table_rows()
{
string sql(120)
long sql_id
double rows


rows = 0
error.bypass = 1
sql = "select count(*):1 from " & table.name
sql_id = sql.parse(sql)
if sql_id<>0 then
sql.select.bind(sql_id, 1, rows)
sql.exec(sql_id)
while true
on case sql.fetch(sql_id)
case eendfile:
break
case 0:
break
default:
endcase
break
endwhile
sql.break(sql_id)
sql.close(sql_id)
endif
error.bypass = 0
return(rows)
}

NPRao
12th January 2007, 22:24
Ralph,

You can use Mark's idea of using dynamic SQL and check the return value for sql.fetch() for 506 or ENOTABLE to determine if the table physically exists in the database or not.

Alternatively, you can use the BaaN standard session: ttaad4232m000 - Check Tables

Hitesh Shah
13th January 2007, 17:14
If ur purpose is to create / drop the table based on it's existence , then u can use these function along with error.bypass = 1 (as indicated in Mark's code ) to go ahead . It will work .

_Ralph_
16th January 2007, 19:52
Thank you all

it works!:)