AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Module Coding (https://forums.alliedmods.net/forumdisplay.php?f=9)
-   -   [SQL] MySQL Connector :: Remote Database (+Natives) (https://forums.alliedmods.net/showthread.php?t=227170)

claudiuhks 09-28-2013 08:53

[SQL] MySQL Connector :: Remote Database (+Natives)
 

- MySQL Connector :: Remote Database -



Download
View C++ Source Code
Visit MySQL Page
This extension's purpose is to make the MySQL scripting more easier for anyone. Just look at the INC file which is listed below.
This extension works only with a MySQL server.


PHP Code:

/** Does a query.
 *
 * @param Query                The query to execute.
 * @param Select            Set it true whether the query contains "SELECT" word.
 *
 * @return                    The number of rows selected, if any.
 */
native /* unsigned int */    RemDatabase_Query(Query[], bool:Select false);

/** Retrieves a result.
 *
 * @param Row                The row to pick result from.
 * @param Column            The column to pick result from.
 * @param Buffer            The variable to store result in.
 * @param Size                The variable that represents the buffer size.
 *
 * @return                    The result converted as integer.
 */
native /* signed int */        RemDatabase_Get(RowColumnBuffer[], Size);

/** Makes a string safe.
 *
 * @param String            The string to make safe.
 * @param Character            The character to replace bad characters as '\\', '`', '"' or '\''.
 *
 * @return                    True if success or false if error.
 */
native /* bool */            bool:RemDatabase_Safe(String[], Character '*'); 



An example of plugin may be the one listed below.

PHP Code:

#include amxmodx
#include amxmisc
#include remote_database

public plugin_init()
{
  
register_plugin("Last Played Maps""1.0""Hattrick (Claudiu HKS)");

  
RemDatabase_Query("CREATE TABLE IF NOT EXISTS Maps (Name TEXT, UnixTimeStamp NUMERIC)");

  new 
Map[32], Buffer[256];
  
get_mapname(Mapsizeof(Map) - 1);

  
formatex(Buffersizeof(Buffer) - 1"INSERT INTO Maps VALUES ('%s', %d)"Mapget_systime());

  
RemDatabase_Query(Buffer);

  
register_concmd("amx_lastmaps""CmdLastMaps"ADMIN_MAP"- displays the last played maps");
}

public 
CmdLastMaps(ClientLevelCommand)
{
  if (!
cmd_access(ClientLevelCommand1))
  {
    return 
PLUGIN_HANDLED;
  }

  
console_print(Client"^nThe last played maps were:^n");

  static 
Count 0Iterator 0Map[32];

  
Count RemDatabase_Query("SELECT Name FROM Maps ORDER BY UnixTimeStamp DESC LIMIT 15"true);

  if (
Count)
  {
    for (
Iterator 0Iterator CountIterator++)
    {
      if (
Iterator == 0)
      {
        
RemDatabase_Get(Iterator0Mapsizeof(Map) - 1);

        
console_print(Client"%s (current)"Map);
      }

      else
      {
        
RemDatabase_Get(Iterator0Mapsizeof(Map) - 1);

        
console_print(ClientMap);
      }
    }
  }

  else
  {
    
/* I can't believe I reached here... */
    
console_print(Client"Unfortunately, there were no maps played yet.");
  }

  return 
PLUGIN_HANDLED;




Other information declared below.

Edit and upload RemoteDatabaseInformation.ini to $(MODDIR)/addons/amxmodx/configs.

How to use RemDatabase_Get native?

For example, if you execute the next query while having 5,000 rows into your table: SELECT Apples, Oranges FROM Fruits LIMIT 2

There will be two rows selected, because LIMIT is 2.
There will be two columns selected, because you select both Apples and Oranges.

So, you will use RemDatabase_Get with Row parameter 0 and then with Row parameter 1.
Also, with Column parameter 0 and then with Column parameter 1.



claudiuhks 09-28-2013 08:55

Re: [SQL] MySQL Connector :: Remote Database
 
Here is the Linux version.


TheDS1337 09-28-2013 10:51

Re: [SQL] MySQL Connector :: Remote Database
 
Nice Job!!

JusTGo 09-28-2013 11:13

Re: [SQL] MySQL Connector :: Remote Database
 
sorry for being stupid but waht the diffrent betwen this and this https://forums.alliedmods.net/showthread.php?t=227172

claudiuhks 09-28-2013 13:33

Re: [SQL] MySQL Connector :: Remote Database
 
Quote:

Originally Posted by JusTGo (Post 2042071)
sorry for being stupid but waht the diffrent betwen this and this https://forums.alliedmods.net/showthread.php?t=227172

This one is MySQL and the other one is SQLite. Are two different things. MySQL means a remote connection between client and server and SQLite means a local database stored as a file.

bcKq 09-29-2013 10:24

Re: [SQL] MySQL Connector :: Remote Database
 
What's the difference between this and SQLx?

TheDS1337 09-29-2013 13:31

Re: [SQL] MySQL Connector :: Remote Database
 
Quote:

Originally Posted by bcKq (Post 2042670)
What's the difference between this and SQLx?

This is easy to use, you can do everything with just those 3 natives :)

Mistrick 09-30-2013 10:43

Re: [SQL] MySQL Connector :: Remote Database
 
Only one db connection?

claudiuhks 09-30-2013 13:03

Re: [SQL] MySQL Connector :: Remote Database
 
Quote:

Originally Posted by bcKq (Post 2042670)
What's the difference between this and SQLx?

This one uses a newer MySQL connector version and it's extremely easy to be used.

Quote:

Originally Posted by Mistrick (Post 2043193)
Only one db connection?

Of course, you may use many tables instead of using many connections. In my opinion, many connections are not required. Why to use many connections on a server? You can use for a server a connection and for another server, another connection. The configuration file is placed into the folder named addons instead of besides hlds.exe.

bcKq 10-01-2013 06:54

Re: [SQL] MySQL Connector :: Remote Database (+Natives)
 
It uses threaded queries or just like those SQL_Connect and then SQL_Execute commands?
If it uses the second I think I will give that module a try.


All times are GMT -4. The time now is 09:20.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.