[Include] C-MYSQL (Remade) - Increased Speed & More Simple
#1

C-MySQL
Information

Hi, I recently released a include called C-MySQL, the old include was:
  • Slow
  • Confusing
  • Little opportunity (Speed increasing wise)
Well, I decided to remake the script will some new functions and some functions removed. This time this can be useful.

Setup

There's a new way to set this up now. Instead of the useless parameters that made the include confusing, there are now defines that you can fill out. These defines are below:

pawn Code:
#define ACCOUNT_TABLE ""
#define USERNAME_FIELD ""
#define PASSWORD_FIELD ""
These defines should be filled in as below (This is an example):

pawn Code:
#define ACCOUNT_TABLE "Accounts"
#define USERNAME_FIELD "Username"
#define PASSWORD_FIELD "Password"
If you look inside the include you'll notice this:

pawn Code:
#if defined MYSQL_PLUGIN
    #include <a_mysql>
#else
    #include <mysql>
#endif
If you would like to use Strickenkid's MySQL plugin disable MYSQL_PLUGIN, like below:

pawn Code:
//#define MYSQL_PLUGIN // Defined = BlueG's plugin. | Undefined = Strickenkid's plugin.
These defines are found in the include ( C-MySQL.inc )

Functions (List)

Code:
native CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1);
native CMySQL_Delete(Username[], ThreadID = -1, extraID = -1);
native CMySQL_SetInt(Username[], Field[], Value, ThreadID = -1, extraID = -1);
native CMySQL_CustomDataSet(Username[], Custom[], ThreadID = -1, extraID = -1);
native CMySQL_Set(Username[], Field[], Value[], bool:md5 = false, ThreadID = -1, extraID = -1);
native CMySQL_SetFloat(Username[], Field[], Float:Value, ThreadID = -1, extraID = -1);
native CMySQL_SetBool(Username[], Field[], bool:Value, ThreadID = -1, extraID = -1);
native CMySQL_Load(Username[], ThreadID = -1, extraID = -1);
native CMySQL_Exists(Username[]);
native CMySQL_Int(Username[], Field[], ThreadID = -1, extraID = -1);
native CMySQL_Get(Username[], Field[], Storage[], ThreadID = -1, extraID = -1);
native Float:CMySQL_Float(Username[], Field[],ThreadID = -1, extraID = -1);
Functions (Explanation)

CMySQL_Create(Username[], Password[], bool:md5 = true, ThreadID = -1, extraID = -1)
Username - The account's username.
Password - The account's password.
bool:md5 - If true (default), then it md5 hashes the password, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Create("Carlton", "MyPassword");
MySQL_Delete(Username[], ThreadID = -1, extraID = -1)
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Delete("Carlton");
CMySQL_SetInt(Username[], Field[], Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetInt("Carlton", "AdminLevel", 1337);
CMySQL_CustomDataSet(Username[], Custom[], ThreadID = -1, extraID = -1)
Username - The account's username.
Custom - The custom saving query.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_CustomDataSet("Carlton", "AdminLevel = 1337, Money = 10000, SkinID = 17");
CMySQL_Set(Username[], Field[], Value[], bool:md5 = false, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
bool:md5 - If false (default), then it md5 hashes the value, otherwise it doesn't.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_Set("Carlton", "Password", "MyNewPassword", true);
CMySQL_SetFloat(Username[], Field[], Float:Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetFloat("Carlton", "PosX", 1337.0);
CMySQL_SetBool(Username[], Field[], bool:Value, ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to set the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
CMySQL_SetBool("Carlton", "IsHungry", true);
CMySQL_Load(Username[], ThreadID = -1, extraID = -1);
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the MySQL was successful.
Example:

pawn Code:
#define MYSQL_LOAD_ACCOUNT (0)
CMySQL_Load("Carlton", MYSQL_LOAD_ACCOUNT, playerid);

public OnQueryFinish(...) {
     mysql_store_result();
     ....
}
CMySQL_Exists(Username[])
Username - The account's username.
ThreadID - For threading usages.
extraID - For threading usages.
returns 1 if the account exists.
Example:

pawn Code:
if(CMySQL_Exists("Carlton")) return print("Your account exists!");
CMySQL_Int(Username[], Field[], ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:

pawn Code:
new MyMoney = CMySQL_Int("Carlton", "Money");
CMySQL_Get(Username[], Field[], Storage[], ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
Storage - The string you'd like to store the value to.
ThreadID - For threading usages.
extraID - For threading usages.
returns nothing.
Example:

pawn Code:
new MyEmail[16];
CMySQL_Get("Carlton", "Email", MyEmail);
print(MyEmail);
Float:CMySQL_Float(Username[], Field[],ThreadID = -1, extraID = -1)
Username - The account's username.
Field - The field you would like to get the value from.
ThreadID - For threading usages.
extraID - For threading usages.
returns the value of the field.
Example:

pawn Code:
SetPlayerPos(playerid, CMySQL_Float("Carlton", "CrashPosX"), CMySQL_Float("Carlton", "CrashPosY"), CMySQL_Float("Carlton", "CrashPosZ"),
Example Script

pawn Code:
#include <a_samp>
#include <a_mysql>
#include <zcmd>
#include <sscanf2>

new MyMoney[MAX_PLAYERS], MyKills[MAX_PLAYERS];

stock GetUserName(playerid) {
      new name[24];
      GetPlayerName(playerid, name, 24); return name;
}

CMD:register(playerid, params[]) {
      if(CMySQL_Exists(GetUserName(playerid))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account exists already!");

      new password[32];
      if(sscanf(params, "s[32]", password))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> /register <password>");
 
      if(strlen(password) > 32)
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");
 
      CMySQL_Create(GetUserName(playerid), password);
}

CMD:login(playerid, params[]) {
       if(!CMySQL_Exists(GetUserName(playerid))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your account doesn't exist!");
 
      new password[32];
      if(sscanf(params, "s[32]", password))
           return SendClientMessage(playerid, 0xFFFFFFA, "<> /login <password>");
 
      if(strlen(password) > 32)
           return SendClientMessage(playerid, 0xFFFFFFA, "<> Your password must be 32 characters or less.");

      new Passwordz[32];
      CMySQL_Get(GetUserName(playerid), "Password", Passwordz, true);
      if(!strcmp(Passwordz, password, true)) {
           SendClientMessage(playerid, 0xFFFFFFA, "<> You're now logged.");
           CMySQL_Load(GetUserName(playerid), 1, playerid);
      }
}

stock GetMyAdminLevel(Username[]) {
     return CMySQL_Int(Username, "AdminLevel");
}

public OnPlayerDisconnect(playerid, reason) {
       new string[128];
       format(string, 128, "Money = %i, MyKills = %i", GetPlayerMoney(playerid), GetPlayerScore(playerid));
       CMySQL_CustomDataSet(GetUserName(playerid), string);
}

public OnQueryFinish( query[], resultid, extraid, connectionHandle ) {
      mysql_store_result();
      new Data[128];
      mysql_fetch_row_format(Data, "|");
      sscanf(Data, "p<|>ii", MyMoney[extraid], MyKills[extraid]);
      GivePlayerMoney(playerid, MyMoney[extraid]);
}
Requirements

You will need either BlueG's or Strickenkids plugin, these can be found below:

http://forum.sa-mp.com/forumdisplay.php?f=18

Thanks to

Strickenkid - Plugin.
BlueG - Plugin.

Download

Click below.
Reply
#2

Nice to see the new version, great work as always

Btw, does this one now work with other versions of SMF than just 1.0?
Reply
#3

FFS

i clicked epic missions to try and rip some stuff out of a game mode or filter script and it brings me to download link

im gunna sue you.




Anyways, i like the functions good job
Reply
#4

Quote:
Originally Posted by Grim_
View Post
Nice to see the new version, great work as always

Btw, does this one now work with other versions of SMF than just 1.0?
This is not C-SMF
Reply
#5

Wow... I feel stupid :P

Still nice work
Reply
#6

DDDDDDDDD yay ty!
Reply
#7

Thank you.
Reply
#8

Thats cool, but where is a_mysql.inc ? id ont find it in this topic...

Note: I find it and it works fine..thanks a lot!
Reply
#9

http://files.g-stylezzz.com/mysql/re...win32_vs10.rar
Reply
#10

A very nice inlcude !
but
CMySQL_Exists("Name")

Has a little Bug...
undefined symbol "ThreadID"
Reply
#11

Oh, yeah, I had fixed this bug but never uploaded it, sorry. http://solidfiles.com/d/6205/
Reply
#12

Thanks for uploading
But i have another Problem:

if(dialogid == REGISTER_DIALOG)
{
if(strlen(inputtext) <= 30 || strlen(inputtext) >= 3)
{
new PlayerName[64];
GetPlayerName(playerid,PlayerName,sizeof(PlayerNam e));
CMySQL_Create(PlayerName, inputtext);
SendClientMessage(playerid,FARBE_GELB,"Your account was sucessfull created!");
SendClientMessage(playerid,FARBE_GELB,"At next Login, you will need you password");
LoginSpieler(playerid);
}
else
{
ShowPlayerDialog(playerid,REGISTER_DIALOG,DIALOG_S TYLE_INPUT,"Register","Das Passwort muss mindestens 3 \n und maximal 30 Buchstaben anthalten.","Login","Exit");
}
return 1;
}

The account would not be created...
I hope you could help me.
Reply
#13

Is your database setup, are your fields also correct, and do you have debugging enabled?
Reply
#14

In another public or stock it works.
Must i make a Timer, for more Time for the query?
I donґt know...?
Reply
#15

I didn't understand you clearly, if it doesn't work in that specific function, then try fixing why the function isn't being called.
Reply
#16

Ok, thanks, i fixed it!

But now another problem:
At CMySQL_Get(name, "money", SpielerStats[playerid][money]);
It writes 48 into the variable.
In my Database it is an int(8 ) | Dont allow null | standard 0
Reply
#17

Quote:
Originally Posted by [LoD]Hauke
Посмотреть сообщение
Ok, thanks, i fixed it!

But now another problem:
At CMySQL_Get(name, "money", SpielerStats[playerid][money]);
It writes 48 into the variable.
In my Database it is an int(8 ) | Dont allow null | standard 0
CMySQL_Get is used for strings, use CMYSQL_Int, your code should look like this:

pawn Код:
SpielerStats[playerid][money] = CMySQL_Int(name, "money");
Reply
#18

Oh, sorry. Im stupid.
I thought i could use it for both.
thx
Reply
#19

What change when i have MySQL or not?
Reply
#20

Quote:
Originally Posted by Brian_Furious
Посмотреть сообщение
What change when i have MySQL or not?
Click me
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)