Skip to content

Commit

Permalink
Inline handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Misiur committed Mar 12, 2015
1 parent 74bc041 commit 22de9dd
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 24 deletions.
1 change: 1 addition & 0 deletions gamemodes/test.pwn
@@ -1,4 +1,5 @@
#include <a_samp>
#include <YSI\y_inline>
#include <a_mysql>
#define COLOUR_INFO 0xBADA55FF
Expand Down
44 changes: 20 additions & 24 deletions gamemodes/test/houses.inc
Expand Up @@ -29,9 +29,7 @@ new
hook OnGameModeInit()
{
Iter_Init(PlayerHouse);
memset(PlayerHouse[0], INVALID_HOUSE_INDEX, MAX_PLAYERS * MAX_PLAYER_HOUSES);
LoadHouses();
return 1;
Expand Down Expand Up @@ -59,35 +57,33 @@ hook OnPlayerConnect(playerid)
return 1;
}
public OnHousesLoaded()
stock LoadHouses()
{
new
rows = cache_get_row_count(handle)
;
inline HousesLoaded()
{
new
rows = cache_get_row_count(handle)
;
if (!rows) return print("It seems there are no house rows, sorry");
if (!rows) return print("It seems there are no house rows, sorry");
for (new row = 0; row != rows; ++row)
{
if (row == MAX_HOUSES) {
printf("Number of houses in your database (%d) is larger than " #MAX_HOUSES " slots can handle", rows);
for (new row = 0; row != rows; ++row)
{
if (row == MAX_HOUSES) {
printf("Number of houses in your database (%d) is larger than " #MAX_HOUSES " slots can handle", rows);
//We can't load remaining rows :(
break;
}
//We can't load remaining rows :(
break;
}
House[row][hdbID] = cache_get_field_content_int(row, "id", handle);
cache_get_field_content(row, "name", House[row][hName], handle, MAX_HOUSE_NAME);
cache_get_field_content(row, "player_name", House[row][hOwner], handle, MAX_PLAYER_NAME);
Iter_Add(House, row);
House[row][hdbID] = cache_get_field_content_int(row, "id", handle);
cache_get_field_content(row, "name", House[row][hName], handle, MAX_HOUSE_NAME);
cache_get_field_content(row, "player_name", House[row][hOwner], handle, MAX_PLAYER_NAME);
Iter_Add(House, row);
}
}
return 1;
}
stock LoadHouses()
{
mysql_tquery(handle, "SELECT h.*, p.name AS player_name FROM houses h LEFT JOIN player_houses ph ON ph.house_id = h.id LEFT JOIN players p ON p.id = ph.player_id", "OnHousesLoaded");
return mysql_tquery_inline(handle, "SELECT h.*, p.name AS player_name FROM houses h LEFT JOIN player_houses ph ON ph.house_id = h.id LEFT JOIN players p ON p.id = ph.player_id", using inline HousesLoaded, "");
}
AddPlayerHouse(playerid, index, house) {
Expand Down

0 comments on commit 22de9dd

Please sign in to comment.