No Active Cache - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: No Active Cache (
/showthread.php?tid=655738)
No Active Cache -
Dreandor - 28.06.2018
Hey guys,
I want to create objects that are read from my database. However always comes "No Active Cache"
PHP код:
public LoadObject()
{
new mquery[256];
mysql_format(handle, mquery, sizeof(mquery), "SELECT * FROM material");
mysql_pquery(handle, mquery);
new rowsa;
cache_get_row_count(rowsa);
if(rowsa == 0)
{
return 1;
}
else
{
for(new im; im < 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.0, 0.0, 0.0, 0.0, 0);
}
}
return 1;
}
My user accounts are loaded from the database without any problems.
Re: No Active Cache -
Abagail - 28.06.2018
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
Re: No Active Cache -
Calisthenics - 28.06.2018
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.
Re: No Active Cache -
CodeStyle175 - 28.06.2018
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 i; i < r; i++){
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.0, 0.0, 0.0, 0.0, 0);
}
cache_delete(cq);
return 1;
}