AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   error in admin.amxx (https://forums.alliedmods.net/showthread.php?t=196982)

Sutar 09-27-2012 13:38

error in admin.amxx
 
Hi all, so I wrote this script:

Code:

query = SQL_PrepareQuery(sql, "SELECT ...", ip, port)
       
        if(!SQL_Execute(query))
        {
                SQL_QueryError(query, error, 127)
                server_print("SQL error: can't load admins: '%s'!", error)
        } else if(!SQL_NumResults(query)) {
                server_print("No admins found on this server...")
        } else {
                new szFlags[2], szAccess[25]
               
                g_aNum = 0

                while(SQL_MoreResults(query))
                {
                        SQL_ReadResult(query, 1, g_aName[g_aNum], 31)
                        SQL_ReadResult(query, 2, g_aPassword[g_aNum], 15)
                        SQL_ReadResult(query, 3, szAccess, 24)
                        SQL_ReadResult(query, 4, szFlags, 1)
                        SQL_ReadResult(query, 5, g_aDate[g_aNum], 11)
                        SQL_ReadResult(query, 6, g_aLife[g_aNum], 11)
                       
                        g_aAccess[g_aNum] = read_flags(szAccess)
                        g_aFlags[g_aNum] = read_flags(szFlags)
                       
                        ++g_aNum
                        SQL_NextRow(query)
                }

error in line SQL_ReadResult(query, 6, g_aLife[g_aNum], 11)

Here he writes:
Code:

L 09/27/2012 - 20:33:55: [MySQL] Invalid column: 6
L 09/27/2012 - 20:33:55: [AMXX] Displaying debug trace (plugin "admin.amxx")
L 09/27/2012 - 20:33:55: [AMXX] Run time error 10: native error (native "SQL_ReadResult")
L 09/27/2012 - 20:33:55: [AMXX]    [0] admin.sma::adminSql (line 88)
L 09/27/2012 - 20:33:55: [AMXX]    [1] admin.sma::cmdReload (line 109)

How to fix it?

matsi 09-27-2012 14:20

Re: error in admin.amxx
 
You have the answer in the error. "Invalid column". You're trying to read results from column that doesn't exist, make sure its created correctly.

Sutar 09-28-2012 02:20

Re: error in admin.amxx
 
So I did this:
Code:

                new qcolAuth = SQL_FieldNameToNum(query, "username")
                new qcolPass = SQL_FieldNameToNum(query, "password")
                new qcolAccess = SQL_FieldNameToNum(query, "access")
                new qcolFlags = SQL_FieldNameToNum(query, "flags")
                new qcolDate = SQL_FieldNameToNum(query, "adddate")
                new qcolTime = SQL_FieldNameToNum(query, "timelife")
               
                server_print("SQL qcolAuth %d", qcolAuth)
                server_print("SQL qcolPass %d", qcolPass)
                server_print("SQL qcolAccess %d", qcolAccess)
                server_print("SQL qcolFlags %d", qcolFlags)
                server_print("SQL qcolDate %d", qcolDate)
                server_print("SQL qcolTime %d", qcolTime)
               
                while(SQL_MoreResults(query))
                {
                        SQL_ReadResult(query, qcolAuth, g_aName[g_aNum], 31)
                        SQL_ReadResult(query, qcolPass, g_aPassword[g_aNum], 15)
                        SQL_ReadResult(query, qcolAccess, szAccess, 24)
                        SQL_ReadResult(query, qcolFlags, szFlags, 1)
                        SQL_ReadResult(query, qcolDate, g_aDate[g_aNum], 11)
                        SQL_ReadResult(query, qcolTime, g_aLife[g_aNum], 11)
                       
                        g_aAccess[g_aNum] = read_flags(szAccess)
                        g_aFlags[g_aNum] = read_flags(szFlags)
                       
                        ++g_aNum
                        SQL_NextRow(query)
                }

And I found:
Quote:

qcolAuth 0
SQL qcolPass 1
SQL qcolAccess 2
SQL qcolFlags 3
SQL qcolDate 4
SQL qcolTime 5
MySQL reads a field from 0?

YamiKaitou 09-28-2012 02:25

Re: error in admin.amxx
 
SQLx numbers the columns starting at 0, yes


All times are GMT -4. The time now is 08:21.

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