Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What could cause error on this line
Message
 
General information
Forum:
Visual FoxPro
Category:
Other
Environment versions
Visual FoxPro:
VFP 9 SP1
Miscellaneous
Thread ID:
01526039
Message ID:
01526055
Views:
64
>>The problem, as Boris correctly pointed, is that my expression
>>
>>cSqlInsert = "insert into Mytable (fld1, fld2, fld3) values (?MyTable.fld1, ?MyTable.fld2, ?MyTable.fld3)"
>>
>>
>>is very very long. Imagine that you have 30 fields. And this expression is created in a data driven approach scanning fields of the dictionary. Here is a segment of this code:
>>
>>
>>cSqlInsert = "insert into " + ALLTRIM(DICT.TBL_NAME) + " "
>>cSqlInsertValues = "" 
>>
>>DO WHILE !EOF() AND DICT.TBL_NAME = cTableName
>>	
>>   cSqlInsert = cSqlInsert + IIF( EMPTY(cSqlInsertValues),"( ",", ") + ALLTRIM(DICT.FLD_NAME) 
>>		
>>   cSqlInsertValues = cSqlInsertValues + IIF( EMPTY(cSqlInsertValues),"( ",", ") +  "?" + ALLTRIM(DICT.TBL_NAME) + "." + ALLTRIM(DICT.FLD_NAME) 
>>	
>>    SKIP IN DICT
>>
>>ENDDO 
>>
>>cSqlInsert = cSqlInsert + ") VALUES " + cSqlInsertValues + ")"
>>
>>
>>So the above code creates this long cSqlInsert. Any suggestions on what to change?
>
>The code worked OK for me (slight variation). I suggest to use SCAN/ENDSCAN instead of DO WHILE.
>Here is my test code:
>
>
>LOCAL lcAllFields
>
>USE ITEMTREELOG
>
>lnFields = AFIELDS(laFields)
>
>lcAllFields = ''
>
>FOR lnI = 1 TO lnFields
>
>   lcAllFields = m.lcAllFields + IIF(EMPTY(m.lcAllFields),'',', ') + '?' + 'ItemTreeLog.' + laFields(m.lnI,1)
>NEXT
>
>lcInsert = 'insert into ' +  'ITEMTREELOG (' + STRTRAN(m.lcAllFields, '?ItemTreeLog.','') + ') values (' + m.lcAllFields + ')'
>
>_cliptext = m.lcInsert
Thank you.
"The creative process is nothing but a series of crises." Isaac Bashevis Singer
"My experience is that as soon as people are old enough to know better, they don't know anything at all." Oscar Wilde
"If a nation values anything more than freedom, it will lose its freedom; and the irony of it is that if it is comfort or money that it values more, it will lose that too." W.Somerset Maugham
Previous
Reply
Map
View

Click here to load this message in the networking platform