No Active Cache
#1

Hey guys,

I want to create objects that are read from my database. However always comes "No Active Cache"



PHP код:
LoadObject(); 
PHP код:
public LoadObject()
{
    new 
mquery[256];
    
mysql_format(handlemquerysizeof(mquery), "SELECT * FROM material");
    
mysql_pquery(handlemquery);
    new 
rowsa;
    
cache_get_row_count(rowsa);
    if(
rowsa == 0)
    {
        return 
1;
    }
    else
    {
        for(new 
imim sizeof(mquery); im++)
        {
            
cache_get_value_name_int(0"modelid"iMaterial[im][modelid]);
            
cache_get_value_float(0"posx"iMaterial[im][m_x]);
            
cache_get_value_float(0"posy"iMaterial[im][m_y]);
            
cache_get_value_float(0"posz"iMaterial[im][m_z]);
            
cache_get_value_name(0"3dtext"iMaterial[im][mText]);
              
material[im] = CreateDynamicObject(iMaterial[im][modelid],iMaterial[im][m_x],iMaterial[im][m_y],iMaterial[im][m_z] - 1.00.00.00.00);
        }
    }
    return 
1;

My user accounts are loaded from the database without any problems.
Reply
#2

The error is right on point, there is no cache active because it isn't forwarded to a callback. mysql_pquery uses threading, which means a separate callback should be used for handling results.

See SA-MP wiki documentation: https://sampwiki.blast.hk/wiki/MySQL
Reply
#3

Even if you create a callback for it to work, it will not (at least, not as expected).

Your code only retrieves the data from the first row. The first parameter in cache_get_value* functions is the row id which in your case of multiple rows is not 0 but im.

Another problem is that your loop is executed 257 times. It needs to be im < rowsa and of course check that rows will not exceed the size of iMaterial array.
Reply
#4

when you dont enter player text into string there isnt no need to escape format it.
but when you need to load many things i would suggest you to use threaded query.
PHP код:
public LoadObject() 

    new 
Cache:cq=mysql_query(handle,"select * from material"),r=cache_num_rows();
    for(new 
iri++){
        
cache_get_value_name_int(i"modelid"iMaterial[i][modelid]); 
        
cache_get_value_float(i"posx"iMaterial[i][m_x]); 
        
cache_get_value_float(i"posy"iMaterial[i][m_y]); 
        
cache_get_value_float(i"posz"iMaterial[i][m_z]); 
        
cache_get_value_name(i"3dtext"iMaterial[i][mText]); 
        
material[i] = CreateDynamicObject(iMaterial[i][modelid],iMaterial[i][m_x],iMaterial[i][m_y],iMaterial[i][m_z] - 1.00.00.00.00);
    }
    
cache_delete(cq); 
    return 
1

Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)