REAL Software Forums

The forum for REAL Studio and other REAL Software products.
[ REAL Software Website | Board Index ]
It is currently Sun Aug 01, 2010 12:09 am

All times are UTC - 5 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: Making The Code Run Faster Editing Records
PostPosted: Thu Mar 26, 2009 9:37 am 
Offline

Joined: Thu Apr 26, 2007 7:29 am
Posts: 161
Location: Middlebury, CT
Hi,

I have an app that is a multiple choice test, in which the user selects an answer, and is scored on the answer depending which answer he selected. Once answered, the user can not answer the question and change the score again. In order to keep track that the question has already been answered, I have a database table that marks a field with an "X" . When the user exits out of the test, I have code that clears all the Xs out of all the records, so the next time a user starts a test, all the questions will be marked as unanswered. The code I have for doing so is below.

The problem is that it is incredably slow under Windows. It is not so bad on the Mac, but if you have 1800 questions in your recordset, it slows down to a crawl. I was wondering if anyone knew a way to speed up this code or know another way the problem can be handled. Any help would be appreciated.

Code:
  //Erases Already Answered Marks
  Dim VC As Integer
  Dim L as Integer

 
Dim wq as Recordset
Dim rs as Recordset
 
  VC=rs.RecordCount

 
  wq.MoveFirst
 
  For L = 1 to VC
    wq.Edit
    wq.field("XX").StringValue=""
    wq.Update
    Fire5.Commit
    wq.MoveNext
  Next


Top
 Profile E-mail  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Thu Mar 26, 2009 10:00 am 
Offline

Joined: Tue Nov 13, 2007 11:48 am
Posts: 155
Location: Belgium
Isn't it possible to do this in a single sql-statement?
So you don't have to iterate all the records.
Syntax depends on what database-engine your using.

Code:
dim sqlstring as string="update  questionstable set questionstable.answered="" where questionstable.answered=""x"
db.sqlexectute(sqlstring)


Top
 Profile  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Thu Mar 26, 2009 10:06 am 
Offline

Joined: Thu Apr 26, 2007 7:29 am
Posts: 161
Location: Middlebury, CT
Hi Goofie,

That would be great if it could be just one sql statement. I am using the Realbasic database engine. Do you know what that syntax may be?

Jim


Top
 Profile E-mail  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Thu Mar 26, 2009 10:07 am 
Offline

Joined: Tue Nov 13, 2007 11:48 am
Posts: 155
Location: Belgium
pasted some pseudocode in my edited message
Only have mysql-experience, but realbasic should do the same :D
Quote:
For the single-table syntax, the UPDATE statement updates columns of existing rows in the named table with new values. The SET clause indicates which columns to modify and the values they should be given. Each value can be given as an expression, or the keyword DEFAULT to set a column explicitly to its default value. The WHERE clause, if given, specifies the conditions that identify which rows to update. With no WHERE clause, all rows are updated. If the ORDER BY clause is specified, the rows are updated in the order that is specified. The LIMIT clause places a limit on the number of rows that can be updated.


Top
 Profile  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Thu Mar 26, 2009 10:41 am 
Offline

Joined: Thu Apr 26, 2007 7:29 am
Posts: 161
Location: Middlebury, CT
Hi Goofie,

I am trying to take your code and apply it to my situation, but I don't think I have it right since I get an error that the sqlexecute does not exist.

My database name = Fire5
The Table Name = Mark
The Field Name =XX
The recordset - wq

This is the code:

Code:
dim sqlstring as string="update  Mark set XX="" where XX=""X"
Fire5.sqlexectute(sqlstring)


I also tried this in which I did not get any errors but it did do anything

Code:
  Dim sqlstring As String
 
  sqlstring="update  Mark set  XX="" where  XX=""X"
 
  wq=Fire5.SQLSelect(sqlstring)


Can anyone see what may be wrong? Thank you.

Jim


Top
 Profile E-mail  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Thu Mar 26, 2009 10:47 am 
Offline

Joined: Tue Nov 13, 2007 11:48 am
Posts: 155
Location: Belgium
:?:
update Mark set Mark.XX="" where Mark.XX=""X""

You can also debug using the errorcode retrieved from your database
Code:
if db.error then
msgbox db.errormessage
end if


Top
 Profile  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Thu Mar 26, 2009 10:57 am 
Offline

Joined: Thu Apr 26, 2007 7:29 am
Posts: 161
Location: Middlebury, CT
I think I have it.

The correct code is :

Code:
  Dim sqlstring As String
  sqlstring = "update Mark set XX = '' where XX = 'X';"
  wq=Fire5.SQLSelect(sqlstring)


Thanks Goofie for pointing me in the right direction. I really appreciate the help.
:D

Jim


Top
 Profile E-mail  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Fri Mar 27, 2009 4:50 pm 
Offline
User avatar

Joined: Tue Mar 17, 2009 8:53 am
Posts: 751
Knightlite wrote:
I think I have it.

The correct code is :

Code:
  Dim sqlstring As String
  sqlstring = "update Mark set XX = '' where XX = 'X';"
  wq=Fire5.SQLSelect(sqlstring)


Thanks Goofie for pointing me in the right direction. I really appreciate the help.
:D

Jim

I think it should be SQLExecute, not SQLSelect. Also, you don't need the where clause if you're just resetting all of them. So it's just this one statement:
Code:
Fire5.SQLExecute "update Mark set XX=''"

What was wq for?

_________________
No thanks, I don't want to buy any plugins.


Top
 Profile  
 
 Post subject: Re: Making The Code Run Faster Editing Records
PostPosted: Sun Mar 29, 2009 10:49 am 
Offline

Joined: Thu Apr 26, 2007 7:29 am
Posts: 161
Location: Middlebury, CT
Thanks so much Bessie. That code is wicked fast, and worked great.

Thank you again.

Jim


Top
 Profile E-mail  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: Google [Bot] and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group