Raised This Month: $32 Target: $400
 8% 

[SQL] SQLite Connector :: Local Database (+Natives)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 09-28-2013 , 09:06   [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #1


- SQLite Connector :: Local Database -



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


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 */    Database_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 */        Database_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:Database_Safe(String[], Character '*'); 


An example of plugin may be the one listed below.

PHP Code:
#include amxmodx
#include amxmisc
#include database

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

  
Database_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());

  
Database_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 Database_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;




How to use Database_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 Database_Get with Row parameter 0 and then with Row parameter 1.
Also, with Column parameter 0 and then with Column parameter 1.

__________________

Last edited by claudiuhks; 03-16-2014 at 12:59.
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 09-28-2013 , 09:29   Re: [SQL] SQLite Connector :: Local Database
Reply With Quote #2



Cool stuff.
guipatinador is offline
TheDS1337
Veteran Member
Join Date: Jun 2012
Old 09-28-2013 , 10:52   Re: [SQL] SQLite Connector :: Local Database
Reply With Quote #3

Quote:
Originally Posted by DeagLe.Studio View Post
Nice Job!!
TheDS1337 is offline
claudiuhks
Yam Inside®™℠
Join Date: Jan 2010
Location: Living Randomly
Old 03-08-2014 , 20:15   Re: [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #4

Pushed a build.
__________________
claudiuhks is offline
Send a message via MSN to claudiuhks Send a message via Yahoo to claudiuhks Send a message via Skype™ to claudiuhks
metal_upa
Senior Member
Join Date: Jun 2016
Old 06-07-2016 , 05:24   Re: [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #5

Where is the compiled module with full package? it seems download link is broken.
metal_upa is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 06-10-2016 , 23:27   Re: [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #6

Anyone have a mirror??
WAR3DM is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 06-23-2016 , 01:24   Re: [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #7

Bump
WAR3DM is offline
GordonFreeman (RU)
Veteran Member
Join Date: Jan 2010
Location: Uzbekistan
Old 06-23-2016 , 13:00   Re: [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #8

Why you don't want use SQLx from amxmodx?
__________________
The functional way is the right way
GordonFreeman (RU) is offline
WAR3DM
Senior Member
Join Date: Mar 2016
Old 06-26-2016 , 23:11   Re: [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #9

This looks much simpler.
WAR3DM is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 06-27-2016 , 00:55   Re: [SQL] SQLite Connector :: Local Database (+Natives)
Reply With Quote #10

Quote:
Originally Posted by WAR3DM View Post
This looks much simpler.
You were probably looking at the SQLx threading API, which indeed can be complicated. Non-threaded queries are as simple as this module is.
klippy is offline
Reply



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

Forum Jump


All times are GMT -4. The time now is 12:50.


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