SA-MP Forums

Go Back   SA-MP Forums > SA-MP Scripting and Plugins > Scripting Help

Reply
 
Thread Tools Display Modes
Old 12/08/2019, 12:14 PM   #1
Uberanwar
Gangsta
 
Uberanwar's Avatar
 
Join Date: May 2012
Location: Malaysia
Posts: 844
Reputation: 62
Default [MySQL] cache_get_row_count: no active cache

I have this error "cache_get_row_count: no active cache". How can I fix it? It has something to do with the codes below.

Code:
GetPlayerUserKeys(playerid)
{
	new query[90];

	mysql_format(g_iHandle, query, sizeof(query), "SELECT * FROM user_keys WHERE owner_id = '%d'", PlayerData[playerid][pID]);
	mysql_tquery(g_iHandle, query);

	return cache_num_rows();
}

GetPlayerVehicleCount(playerid, bool:tooBike = true)
{
  	new query[90];
  	new count;

  	mysql_format(g_iHandle, query, sizeof(query), "SELECT * FROM vehicles WHERE owner_id = '%d'", PlayerData[playerid][pID]);
  	mysql_tquery(g_iHandle, query);

  	for(new j; j < cache_num_rows(); j++)
  	{
    	new tmpModel = cache_get_field_int(j, "model");
    	if(tooBike == false) if(tmpModel == 509 || tmpModel == 481 || tmpModel == 510) continue;
    	count++;
  	}

  	return count;
}
Uberanwar is offline   Reply With Quote
Old 12/08/2019, 12:38 PM   #2
Calisthenics
Gangsta
 
Join Date: May 2018
Posts: 662
Reputation: 96
Default Re: [MySQL] cache_get_row_count: no active cache

mysql_tquery is for threaded queries. If you want to return the value directly (non-threaded), you have to use mysql_query.

For counting rows, you should use COUNT() aggregate function. `onwer_id` is a foreign key but if the index is missing, create one for owner_id and a composite index (owner_id,model). The order matters, owner_id is const so it must be first.

Execute these once:
pawn Code:
ALTER TABLE `vehicles` ADD INDEX `owner_id` (`owner_id`);
ALTER TABLE `vehicles` ADD INDEX `owner_id_model` (`owner_id`, `model`);

pawn Code:
GetPlayerVehicleCount(playerid, bool: tooBike = true)
{
    new query[100], count, Cache: cache_id;

    if (tooBike)
    {
        mysql_format(g_iHandle, query, sizeof(query), "SELECT COUNT(owner_id) FROM vehicles WHERE owner_id = %d", PlayerData[playerid][pID]);
    }
    else
    {
        mysql_format(g_iHandle, query, sizeof(query), "SELECT COUNT(owner_id) FROM vehicles WHERE owner_id = %d AND model NOT IN (509, 481, 510)", PlayerData[playerid][pID]);
    }

    cache_id = mysql_query(g_iHandle, query);
    count = cache_get_field_int(0, 0);
    cache_delete(cache_id);
    return count;
}

Now based on the function above, you can see how to use COUNT(), mysql_query and cache functions to modify GetPlayerUserKeys and fix the warning.
Calisthenics is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MySQL: no active cache zowzow Scripting Help 2 26/06/2019 01:04 PM
[ERROR] cache_get_row_count: no active cache AlfaSufaIndo Scripting Help 5 02/07/2018 04:54 PM
mysql_log flood (cache_get_row_count - no active cache) PavelKZ Русский/Russian 1 02/07/2017 02:33 PM
MYSQL - R34 - No active cache MikeEd Scripting Help 10 10/09/2014 01:21 AM
No active cache - MySQL Kindred Scripting Help 2 23/05/2013 07:42 PM


All times are GMT. The time now is 01:48 AM.


Powered by vBulletin® Version 3.8.6
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.