Raised This Month: $ Target: $400
 0% 

Sql Problem


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
[M]xxxx
Member
Join Date: May 2008
Location: Estonia
Old 02-25-2009 , 00:09   Sql Problem
Reply With Quote #1

What wrong?
Code:
L 02/24/2009 - 19:50:12: [MySQL] Invalid DBI result handle -1
L 02/24/2009 - 19:50:12: [AMXX] Displaying debug trace (plugin "sms.amxx")
L 02/24/2009 - 19:50:12: [AMXX] Run time error 10: native error (native "dbi_field")
L 02/24/2009 - 19:50:12: [AMXX]    [0] phpwVdTWV.sma::func_get_sms (line 40)
.sma
Code:
#include <amxmodx>
#include <amxmisc>
#include <dbi>

#define PLUGIN "Plugin"
#define VERSION "Version"
#define AUTHOR "Author"

#define hostname "hostname"
#define sqluser "sqluser"
#define sqlpass "sqlpass"
#define sqldb "sqldb"

new Sql:dbc;
new Result:result;

public plugin_init()
{
  register_plugin(PLUGIN, VERSION, AUTHOR);
  register_clcmd("say /sms", "Show_Sms_Motd");
  register_clcmd("say_team /sms", "Show_Sms_Motd");
  
  new error[289];
  dbc = dbi_connect(hostname, sqluser, sqlpass, sqldb, error, 288);
  
  set_task(300.0, "func_get_sms", 0, "", 0, "b")
}

public Show_Sms_Motd(id)
{
       show_motd(id, "sms.txt")
}

public func_get_sms()
{
result = dbi_query(dbc, "SELECT `Time`, `Message` FROM `sms_chat` ORDER BY `Time` DESC");
new field1;
new field2[32];

field1 = dbi_field(result, 1);
dbi_field(result, 2, field2, 31);

client_print(0, print_chat, "LAST SMS: on %d, with text %s", field1, field2);
}
It dosent show message :S
if i but time to like 25 sec it does about 4-5 times then same error starts
and compling dosent give me any errors
[M]xxxx is offline
Send a message via MSN to [M]xxxx
Dr.G
Senior Member
Join Date: Nov 2008
Old 02-25-2009 , 12:10   Re: Sql Problem
Reply With Quote #2

you should use sqlx... an i THINK it would look something like this:

Code:
 
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <fun>
////////////////////////////////////////////////////////////////////////////////////////////////////
new Host[64],User[64],Pass[64],Db[64]
new error[256], errorcode
new Handle:sql_makedbtuple
new Handle:sql_connect
////////////////////////////////////////////////////////////////////////////////////////////////////
public plugin_init() 
{ 
 
 register_clcmd("say /sms", "Show_Sms_Motd");
 register_clcmd("say_team /sms", "Show_Sms_Motd");
 
 get_cvar_string("amx_sql_host",Host,63)
 get_cvar_string("amx_sql_user",User,63)
 get_cvar_string("amx_sql_pass",Pass,63)
 get_cvar_string("amx_sql_db",Db,63)
 
 sql_makedbtuple = SQL_MakeDbTuple(Host,User,Pass,Db)
 sql_connect = SQL_Connect(sql_makedbtuple, errorcode, error, 255)
 
 
 if (!sql_connect)
 {
  log_amx("Error (%d): %s", errorcode, error)
  console_print(0,"Error (%d): %s", errorcode, error)
  set_fail_state("Can't connect to DB!")
  return PLUGIN_HANDLED
 }
 set_task(300.0, "func_get_sms", 0, "", 0, "b")
 return PLUGIN_HANDLED
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public Show_Sms_Motd(id)
{
       show_motd(id, "sms.txt")
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public func_get_sms()
{
 new result1
 new result2
 
 new Handle:query = SQL_PrepareQuery(sql_connect, "SELECT `Time`, `Message` FROM `sms_chat` ORDER BY `Time` DESC")
 SQL_Execute(query)
 
 result1 = SQL_ReadResult(query, 1)
 result2 = SQL_ReadResult(query, 2)
 
 SQL_FreeHandle(query)
 
 client_print(0, print_chat, "LAST SMS: on %d, with text %s", result1, result2)
 
}
////////////////////////////////////////////////////////////////////////////////////////////////////
__________________

Last edited by Dr.G; 02-26-2009 at 17:02.
Dr.G is offline
[M]xxxx
Member
Join Date: May 2008
Location: Estonia
Old 02-26-2009 , 14:36   Re: Sql Problem
Reply With Quote #3

still native errors :S
[M]xxxx is offline
Send a message via MSN to [M]xxxx
[M]xxxx
Member
Join Date: May 2008
Location: Estonia
Old 02-28-2009 , 12:18   Re: Sql Problem
Reply With Quote #4

Help?
[M]xxxx is offline
Send a message via MSN to [M]xxxx
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 02-28-2009 , 12:35   Re: Sql Problem
Reply With Quote #5

Colum start with 0.

result1 = SQL_ReadResult(query, 0)
result2 = SQL_ReadResult(query, 1)
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
[M]xxxx
Member
Join Date: May 2008
Location: Estonia
Old 02-28-2009 , 14:40   Re: Sql Problem
Reply With Quote #6

Still I Dont know what to do first 2-3 minutes it works fine and then
Code:
L 02/28/2009 - 21:34:29: [MySQL] No result set in this query!
L 02/28/2009 - 21:34:29: [AMXX] Displaying debug trace (plugin "sms.amxx")
L 02/28/2009 - 21:34:29: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 02/28/2009 - 21:34:29: [AMXX]    [0] phpClQP4s.sma::func_get_sms (line 56)
Sma
Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <fun>
////////////////////////////////////////////////////////////////////////////////////////////////////
new Host[64],User[64],Pass[64],Db[64]
new error[256], errorcode
new Handle:sql_makedbtuple
new Handle:sql_connect
////////////////////////////////////////////////////////////////////////////////////////////////////
public plugin_init() 
{ 
 
 register_clcmd("say /sms", "Show_Sms_Motd");
 register_clcmd("say /showsms", "func_get_sms");
 register_clcmd("say_team /sms", "Show_Sms_Motd");
 
 register_cvar("amx_sql_host", "host")
 register_cvar("amx_sql_user", "user")
 register_cvar("amx_sql_pass", "pass")
 register_cvar("amx_sql_db", "db")
 
 get_cvar_string("amx_sql_host",Host,63)
 get_cvar_string("amx_sql_user",User,63)
 get_cvar_string("amx_sql_pass",Pass,63)
 get_cvar_string("amx_sql_db",Db,63)
 
 sql_makedbtuple = SQL_MakeDbTuple(Host,User,Pass,Db)
 sql_connect = SQL_Connect(sql_makedbtuple, errorcode, error, 255)
 
 
 if (!sql_connect)
 {
  log_amx("Error (%d): %s", errorcode, error)
  console_print(0,"Error (%d): %s", errorcode, error)
  set_fail_state("Can't connect to DB!")
  return PLUGIN_HANDLED
 }
 set_task(300.0, "func_get_sms", 0, "", 0, "b")
 return PLUGIN_HANDLED
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public Show_Sms_Motd(id)
{
       show_motd(id, "sms.txt")
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public func_get_sms()
{
 new result1
 new result2
 
 new Handle:query = SQL_PrepareQuery(sql_connect, "SELECT `Time`, `Message` FROM `sms_chat` ORDER BY `Time` DESC")
 SQL_Execute(query)
 
 result1 = SQL_ReadResult(query, 0)
 result2 = SQL_ReadResult(query, 1)
 
 SQL_FreeHandle(query)
 
 client_print(0, print_chat, "LAST SMS: on %d, with text %s", result1, result2)
 
}
////////////////////////////////////////////////////////////////////////////////////////////////////
[M]xxxx is offline
Send a message via MSN to [M]xxxx
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 02-28-2009 , 15:02   Re: Sql Problem
Reply With Quote #7

For text you have to use string

new result2[192]

SQL_ReadResult(query, 1, result2, 191)
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
[M]xxxx
Member
Join Date: May 2008
Location: Estonia
Old 02-28-2009 , 16:20   Re: Sql Problem
Reply With Quote #8

Still errors! i dont know why :S
So Mb someone can to me a new plugin?
i only want to show latest message some info text on next line

[SMS]: message show
For more type /sms
[M]xxxx is offline
Send a message via MSN to [M]xxxx
AntiBots
Veteran Member
Join Date: May 2008
Location: Brazil
Old 02-28-2009 , 21:43   Re: Sql Problem
Reply With Quote #9

PHP Code:
public func_get_sms()

    new 
Handle:query SQL_PrepareQuery(sql_connect"SELECT `Time`, `Message` FROM `sms_chat` ORDER BY `Time` DESC")
    
    if( 
SQL_Execute(query) )
    {
        if( 
SQL_MoreResults(query) )
        {
            new 
resultado[2][192]
            
SQL_ReadResult(query0resultado[0], 191)
            
SQL_ReadResult(query1resultado[1], 191)
            
            
client_print(0print_chat"LAST SMS: on %s, with text %s"resultado[0], resultado[1]) 
        }
        
        
SQL_FreeHandle(query)
    }

You me your tables
__________________
AntiBots is offline
Send a message via ICQ to AntiBots Send a message via MSN to AntiBots Send a message via Skype™ to AntiBots
[M]xxxx
Member
Join Date: May 2008
Location: Estonia
Old 03-04-2009 , 15:30   Re: Sql Problem
Reply With Quote #10

Now it shows no errors! some time when map is loaded it shows no message,
or when new map is and i type /showsms it shows and 5 minutes is passed it dosent show message!
when server starts it gives error that cant connect to db! map changed no db connect error.

Tables
Code:
CREATE TABLE `sms_chat`(
    `Sender` varchar(12) NOT NULL,
    `Message` varchar(255) NOT NULL,
    `Time` varchar(255) NOT NULL
)
.sma
Code:
#include <amxmodx>
#include <amxmisc>
#include <sqlx>
#include <fun>
////////////////////////////////////////////////////////////////////////////////////////////////////
#define PLUGIN "SMS Show"
#define VERSION "0.1"
#define AUTHOR "author"
////////////////////////////////////////////////////////////////////////////////////////////////////
new Host[64],User[64],Pass[64],Db[64]
new error[256], errorcode
new Handle:sql_makedbtuple
new Handle:sql_connect
////////////////////////////////////////////////////////////////////////////////////////////////////
public plugin_init() { 
 register_plugin(PLUGIN, VERSION, AUTHOR)
 register_clcmd("say /sms", "Show_Sms_Motd");
 register_clcmd("say /showsms", "func_get_sms");
 register_clcmd("say_team /sms", "Show_Sms_Motd");
 
 register_cvar("amx_sql_host", "host")
 register_cvar("amx_sql_user", "user")
 register_cvar("amx_sql_pass", "pass")
 register_cvar("amx_sql_db", "db")
 
 get_cvar_string("amx_sql_host",Host,63)
 get_cvar_string("amx_sql_user",User,63)
 get_cvar_string("amx_sql_pass",Pass,63)
 get_cvar_string("amx_sql_db",Db,63)
 
 sql_makedbtuple = SQL_MakeDbTuple(Host,User,Pass,Db)
 sql_connect = SQL_Connect(sql_makedbtuple, errorcode, error, 255)
 
 
 if (!sql_connect)
 {
  log_amx("Error (%d): %s", errorcode, error)
  console_print(0,"Error (%d): %s", errorcode, error)
  set_fail_state("Can't connect to DB!")
  return PLUGIN_HANDLED
 }
 set_task(300.0, "func_get_sms", 0, "", 0, "b")
 return PLUGIN_HANDLED
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public Show_Sms_Motd(id)
{
       show_motd(id, "sms.txt")
}
////////////////////////////////////////////////////////////////////////////////////////////////////
public func_get_sms()
{ 
    new Handle:query = SQL_PrepareQuery(sql_connect, "SELECT `Time`, `Message` FROM `sms_chat` ORDER BY `Time` DESC")
    
    if( SQL_Execute(query) )
    {
        if( SQL_MoreResults(query) )
        {
            new resultado[2][192]
            SQL_ReadResult(query, 0, resultado[0], 191)
            SQL_ReadResult(query, 1, resultado[1], 191)
            
            client_print(0, print_chat, "LAST SMS: on %s, with text %s", resultado[0], resultado[1]) 
        }
        
        SQL_FreeHandle(query)
    }
}  
////////////////////////////////////////////////////////////////////////////////////////////////////
[M]xxxx is offline
Send a message via MSN to [M]xxxx
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 17:01.


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