V4MD - Crash Problem

Ruslan Zasukhin sunshine at public.kherson.ua
Thu Jul 20 09:22:17 CDT 2006


On 7/20/06 4:27 AM, "Sean Wilson" <snw at paradise.net.nz> wrote:

>> on addMyFolder me, folderStr
>>   put "addMyFolder" && folderStr
>>   tFolderSearch = mDatabase.sqlSelect("SELECT ** FROM my_words WHERE
>> folder='"& folderStr &"'")
>> 
>>   if tFolderSearch.recordCount = 0 then
>>     mMyWords.setBlank()
>>     mMyWords.Field("folder").value=folderStr
>>     mMyWords.Field("type").value="myfolder"
>>     mMyWords.Field("realword").value=" "
>>     mMyWords.Field("definition").value=" "
>>     mMyWords.Field("example").value=" "
>>     mMyWords.Field("posp").value=" "
>>     mMyWords.addRecord()
>>   end if
>>   tFolderSearch=void
>> 
>> end
> 
> <snip>
> I don't remember details for 2.2, but shouldn't cursors created with
> DB.sqlSelect() also take cursorLocation, lockType and cursorDirection
> parameters?
> 
> I don't know how safe it is to mix your approaches like you seem to
> be doing above. It looks like you're using the "sql-way" to determine
> whether your table has a record for the entry you're about to add,
> and then the "api-way" to populate fields. Obviously Ruslan is the
> authority - and will hopefully provide better assistance that I can -
> but I'm sure I've seen him recommending not to mix "syntaxes" like that.

Well, here this is not an issue I think.

1) SQL Cursor was made to check if exists record that in field "folder" have
some value. 


2) then NEW record is added via API. New record do not conflict with records
of cursor that can be locked.


3) BTW, it is more safe and accurate write next:

-----------------------------------------------------------
on addMyFolder me, folderStr

   // TASK 1 -- check if record exists:
   put "addMyFolder" && folderStr
   tFolderSearch = mDatabase.sqlSelect("SELECT ** FROM my_words WHERE
folder='"& folderStr &"'")

    recExists = tFolderSearch.recordCount > 0
    tFolderSearch = VOID  -- we do not need cursor any more.
    

  // TASK 2 -- ADD new record:
   if recExists = false then
     mMyWords.setBlank()
     mMyWords.Field("folder").value=folderStr
     mMyWords.Field("type").value="myfolder"
     mMyWords.Field("realword").value=" "
     mMyWords.Field("definition").value=" "
     mMyWords.Field("example").value=" "
     mMyWords.Field("posp").value=" "
     mMyWords.addRecord()
   end if

end
-----------------------------------------------------------


4) actually you can use API way also to define if record exists:

on addMyFolder me, folderStr

   if myWords.Field("folder").ValueExists( folderStr ) then
     mMyWords.setBlank()
     mMyWords.Field("folder").value=folderStr
     mMyWords.Field("type").value="myfolder"
     mMyWords.Field("realword").value=" "
     mMyWords.Field("definition").value=" "
     mMyWords.Field("example").value=" "
     mMyWords.Field("posp").value=" "
     mMyWords.addRecord()
   end if
end
-----------------------------------------------------------


5) To switch to SQL you need build INSERT command using or not using
binding:

A) 

  // TASK 2 -- ADD new record:
   if recExists = false then
       cmd = "INSERT INTO my_words(folder,type,realworld,definition,example,
posp) VALUES(folderStr,myfolder, , , , , )
    
        -- am I right that in Lingo we can put variable names
        -- into string and Lingo put values in fact ?
        -- if no, then you need concat

       db.SqlExecute( cmd )

   end if

end


B) using binding:

  // TASK 2 -- ADD new record:
   if recExists = false then
       cmd = "INSERT INTO my_words(folder,type,realworld,definition,example,
posp) VALUES( :1, :2, :3, :4, :5, :6 )
    
       db.SqlExecute( cmd, [folderStr,myfolder] )

   end if



-----------------------------------------------------------
6) I have take a look on this

   if myWords.Field("folder").ValueExists( folderStr ) then
     mMyWords.setBlank()
     mMyWords.Field("folder").value=folderStr
     mMyWords.Field("type").value="myfolder"
     mMyWords.Field("realword").value=" "
     mMyWords.Field("definition").value=" "
     mMyWords.Field("example").value=" "
     mMyWords.Field("posp").value=" "
     mMyWords.addRecord()
   end if

What means 
     mMyWords.Field("definition").value=" "

You want put string with one space ??  Why?
You have made setBlank. Now it is enough

   if myWords.Field("folder").ValueExists( folderStr ) then
     mMyWords.setBlank()
     mMyWords.Field("folder").value=folderStr
     mMyWords.Field("type").value="myfolder"
     mMyWords.addRecord()
   end if

Not mentioned fields will be empty or NULL



-- 
Best regards,

Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc

Valentina - Joining Worlds of Information
http://www.paradigmasoft.com

[I feel the need: the need for speed]




More information about the Valentina mailing list