Jump to content


Photo

Tunning my script


  • Please log in to reply
1 reply to this topic

#1 wolves

wolves
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 02 August 2006 - 12:06 PM

Hi, in my system, when I have to delete some register I need to verify all other tables that uses references from the register I want to delete.
so I have a array that contains all references like this...

 $ref = Array
(
    [0] => cfo0001=cfo0006.cd_abs
    [1] => cfo0001=cfo0017.cd_pod
    [1] => cfo0004=cfo0011.cd_sor
)

   cfo0001=cfo0006.cd_abs
   my primary key of the table cfo0001 is used  on the table cfo0006 field cd_abs

   so I use a function that loops through the array verifing all references by using this function


#$conn, database connection
#$table, table that I will veirfy
#$pkvalue, value for search
function reflist_have_registers($conn,$table,$pkvalue) {  
  $table = strtolower($table);
  #loads my array
  $list = load_reflist();
  #order the tables by sequence
  sort($list);
  while(list($key,$value) = each($list)) {
    $line = new RefListUtils($value);    
    #I use this to get the table name, table reference, and field name
    # EX cfo0004=cfo0011.cd_sor
    #   line->table1 = cfo0004
    #   line->table2 = cfo0011
    #   line->field    = cd_sor
    
    #ok is the table that I have to verify, lets loop
    if($table == $line->table1) {
      for(($i=key($list)-1);$i<count($list);$i++) {
        //it's not the table, lets get out
        if ($line->table1 != $table)
          break 2;
        $table2 = $line->table2;
        $field = $line->field;
        #this functions runs a query equivalent "select count(field) from table where field = myvalue" 
        if(lookFieldSql($conn,$table2,$field,"{$field} = ?",$pkvalue,'COUNT')>0)
          return true;
      }
    }
  }
  return false;
}

ok it works, but is too slowly, I need a faster way to do this, something that tunes my functions, I don't know, because it's too slowly,

can someone help me?

tks




#2 wolves

wolves
  • Members
  • PipPipPip
  • Advanced Member
  • 65 posts

Posted 02 August 2006 - 12:42 PM

My function had an error,

It was looping all the array when It found the table,
I ne

after this point
if($table == $line->table1) {
      for(($i=key($list)-1);$i<count($list);$i++) {
           ...


I need to put

if($table == $line->table1) {
      for(($i=key($list)-1);$i<count($list);$i++) {
           #to get the new value of table
           $line = new RefListUtils($list[$i]);  ...

its running good now, but if someone have some idea, please tell me

tks






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users