Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Create a Table programmatically
Message
 
 
To
03/10/2001 03:04:31
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00562933
Message ID:
00563581
Views:
29
>>>>>Please help:
>>>>> I'm trying to create a universal data import table based upon the content of another table I call 'schema'. Schema contains the field names, length, type and start and end points of the fields to be imported from a ASCII file. I'm hung up on creating the new data table using just variables to declare the fields. Here is my latest version of code, and it keeps erroring out on the "Alter Table" command.
>>>>>
>>>>>I really appreciate your help.
>>>>>
>>>>>Bob Ohrstedt
>>>>>RJO Associates
>>>>>
>>>>>LOCAL lcfile, lcalias, lcreclen, lafields, ;
>>         <b>lcClause, lnCount, lcFieldName, lcType, lnLength</b>
>>>>><b>#DEFINE MAX_CLAUSES 20</b>
>>>>>IF NOT USED('schema')
>>>>>	USE schema IN 0 SHARED
>>>>>ENDIF
>>>>>
>>>>>CREATE TABLE OhioStreets(fieldnum I(4))
>>>>>
>>>>>IF NOT used('OhioStreets')
>>>>>	USE OhioStreets IN 0 EXCLUSIVE
>>>>>ENDIF
>>>>><b>lcClause = ""
>>>> lnCount=0</b>
>>>>>
>>>>>lcfields = ""
>>>>>SELECT schema
>>>>>SCAN
>>>>>	<b>lnCount=m.lnCount +1</b>
>>>>>	lcFieldName = schema.desc
>>>>>	lnLength = schema.length
>>>>>	lcType = schema.type
>>>>>	<b>lcClause = m.lcClause+ " ADD Column "+ ;
>>>>        m.lcFieldName+" "+ m.lcType+'('+transform(m.lnLenght)+')'
>>>>        if m.lnCount>= MAX_CLAUSES
>>>>           alter table OhioStreets &lcClause
>>>>>	      lnCount=0
>>>>           lcClause =""
>>>>       endif</b>
>>>>>ENDSCAN
>>>><b>if !empty(m.lcClause) && Remainder
>>>>    alter table OhioStreets &lcClause
>>>>endif</b>
>>>>
>>>>See the changes, I made in code.
>>>
>>>I see but would you decipher :)
>>>Cetin
>>
>>Ok, I'll try: my changes now in bold. :)
>Oh I meant the purpose :)ie: What's that magic MAX_CLAUSES number ? Or if it's a well known thing would this ever work w/o a syntax error ? If this works what's superiority to plain 'alter table tablename add column &lcField &lcType(lnLength)' etc ?
>Cetin

The MAX_CLAUSES is empirically found magic number :) If you have a huge table, and you make lots of changes, it may take a long time, so it's much better to do just one ALTER TABLE command. Actually, it's mostly about changing structure, not adding fields, but I think, the same rule still applies. I have DataDictionary application, which allows to add fields/delete fields/change structure in our main database. It's a quite compicated program, so I don't want to show it all, but this idea is borrowed from there.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform