[Tutorial] [BUD]Blazing User Database | Complete documentation
#1

Blazing User Database | Complete tutorial
Written by Rock
Choose what you want to learn:
1. Creating database and columns
2. Save and extract data from the database
3. Set and extract data DIRECTLY into/from database
4. Last set of functions which BUD have.



You will learn how to use these functions:
Код:
        BUD::Setting( setting[], value )
bool    BUD::Initialize( )
bool    BUD::Exit( )
        BUD::VerifyColumn( column[], type[, default value ] )
bool    BUD::IsNameRegistered( name[] )
bool    BUD::RegisterName( name[], password[] )
        BUD::UnregisterName( name[] )
bool    BUD::CheckAuth( name[], password[] )
        BUD::GetNameUID( name[] )
Float   BUD::GetFloatEntry( uid, entry[] )
        BUD::GetIntEntry( uid, entry[] )
        BUD::GetStringEntry( uid, entry[], &value[][, size ] )
bool    BUD::MultiGet( uid, type definitions, ( entry, &variable )... )
bool    BUD::MultiSet( uid, type definitions, ( entry, value )... )
bool    BUD::SetIntEntry( uid, entry[], value )
bool    BUD::SetFloatEntry( uid, entry[], Float:value )
bool    BUD::SetStringEntry( uid, entry[], value[][, size ] )
        BUD::RunQuery( query[], bool:store_results )
        BUD::EscapeSqlString( string[ ] )
        BUD::GetSortedData( &results[][],  column )
bool    BUD::GetNamesForSortedData( results[][], num_results, &names[][] )
The beginning:

Before include BUD we need to have this defined
pawn Код:
#define BUD_USE_WHIRLPOOL false // false - if you don't want to use the WHIRLPOOL plugin and true if we use it
#define BUD_MAX_COLUMNS 10 // 10 - max number of columns witch will be alowed in the database
After we defined this we can include BUD
pawn Код:
#include < BUD >
Now that we included BUD we can begin to use it
Next, go to OnGameModeInit if it's a gamemode or OnfilterScriptInit if it's fs

pawn Код:
public OnFilterScriptInit( )
{

}
Between brackets add:
pawn Код:
BUD::Setting(  opt.Database, "Users.db"  ); // "Users.db" will be the name of the database we create
BUD::Setting(  opt.Asynchronous, true    ); // If it's true it will be faster but in case of anything happens with your computer the database can be corrupted.
BUD::Setting(  opt.KeepAliveTime, 3000   ); // The database will remain active vor 3000 milliseconds after it's used, this is useful for performance
BUD::Setting(  opt.CheckForUpdates, true ); // Name says it all, true if you want to search for updates
After all those setting in same callback we need to initialize the database
WARNING: This must be done before we will use any of it's functions
pawn Код:
BUD::Initialize( );
After we make the settings now we will create columns on the database
pawn Код:
BUD::VerifyColumn(  "Money", BUD::TYPE_NUMBER );
Money - Name of the column
BUD::TYPE:
TYPE_NUMBER: Numbers (1,2,3, 34343)
TYPE_STRING : String(bla, test, rock)
TYPE_FLOAT : Float(2.0, 3.2, 34.33)
TYPE_BINARY : Not supported yet, this will be in the next version

Optional parameters for VerifyColumn:
pawn Код:
BUD::VerifyColumn(  "Money", BUD::TYPE_NUMBER, 50 ); // 50 - optional parameter, this will add value 50 to column "Money" when it's created
Optional parameters can be used also for strings and floats the same way.
If it's a string do like this:
pawn Код:
BUD::VerifyColumn(  "Rank", BUD::TYPE_STRING, "Newbie"  );
After we are done with the settings and columns, go to OnFilterScriptExit or OnGameModeExit if it's a gamemode and add:
pawn Код:
BUD::Exit( );
ATTENTION: Use BUD::Exit( ) ONLY under OnGameModeExit or OnFilterScriptExit and no more elsewhere!

At the end your script will look like this:
pawn Код:
#include < a_samp >

#define BUD_USE_WHIRLPOOL false
#define BUD_MAX_COLUMNS 10

#include < BUD >

public OnFilterScriptInit( )
{
   BUD::Setting(  opt.Database, "Users.db"  );
   BUD::Setting(  opt.Asynchronous, true    );
   BUD::Setting(  opt.KeepAliveTime, 3000   );
   BUD::Setting(  opt.CheckForUpdates, true );

   BUD::Initialize( );
   BUD::VerifyColumn(  "Points", BUD::TYPE_NUMBER  );

   // With optional parameter
   BUD::VerifyColumn(  "Money",  BUD::TYPE_NUMBER, 50  );
   BUD::VerifyColumn(  "Rank",   BUD::TYPE_STRING, "Newbie"  );
   BUD::VerifyColumn(  "Health", BUD::TYPE_FLOAT, 100.00  );
}

public OnFilterScriptExit( )
{
   BUD::Exit( );
}
Read below for the next parts.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)