Raised This Month: $ Target: $400
 0% 

Error in simple multiplication


Post New Thread Reply   
 
Thread Tools Display Modes
API
Veteran Member
Join Date: May 2006
Old 04-13-2010 , 04:21   Re: Error in simple multiplication
Reply With Quote #11

Before I explain, you are trying to make an IP into a single cell and be able to turn it back into an IP, correct?
__________________
API is offline
Send a message via AIM to API
n3wton
Senior Member
Join Date: Mar 2010
Old 04-13-2010 , 04:26   Re: Error in simple multiplication
Reply With Quote #12

Not really.
Yes the ip address needs to be turned into a singal number but I'm using geocitylite to work out the city locations from the IP adress. http://www.maxmind.com/app/csv thats where it tells you how to get the data from the ip address to an ip number from which you can query the database to atain the city location.

yours
n3wton
n3wton is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 04-13-2010 , 12:54   Re: Error in simple multiplication
Reply With Quote #13

Regular arithmetics won't work here because SourcePawn doesn't have unsigned cells. Use the shifts already and give up your multiplication.
FaTony is offline
n3wton
Senior Member
Join Date: Mar 2010
Old 04-13-2010 , 13:02   Re: Error in simple multiplication
Reply With Quote #14

but how would I use the shifts, because geoipcity doesnt take just the ipaddress without the dots, it takes it with the multiplication.

Yours
N3wton
n3wton is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-13-2010 , 15:42   Re: Error in simple multiplication
Reply With Quote #15

I don't think his aim here is to pack it into a cell, but rather to be able to use the result of the multiplication as part of the MySQL query, i.e. get a base 10 number out and use it as part of a string.

The solution is simple: perform the multiplication in MySQL. Feed the four segments of the IP address into the query, and multiply each part by whatever you want.

"SELECT 16777216 * 16777216" successfully returns 281474976710656, so I doubt you'll run into any problems with length.
__________________
Scone is offline
n3wton
Senior Member
Join Date: Mar 2010
Old 04-13-2010 , 19:50   Re: Error in simple multiplication
Reply With Quote #16

@Scone
Thats a great idea, but for some unknown reason, its not working, when I manually enter the equation into my own SQlite database it returns the correct value, but when I run the same query via SOurceMod, I still get the negative value

Did you get
Quote:
"SELECT 16777216 * 16777216" successfully returns 281474976710656
Via source mod? if so how?

Here's my code, that I'm using...
Code:
SubIP[0] = "153";
SubIP[1] = "104";
SubIP[2] = "162";
SubIP[3] = "98";
new String:IPseg[256];
Format( IPseg, 256, "SELECT (16777216 * %s) + (65536 * %s) + (256 * %s) + %s", SubIP[0], SubIP[1], SubIP[2], SubIP[3] ); 
new Handle:LocNumberQ = SQL_Query(GeoCityDB, IPseg);
SQL_FetchRow( LocNumberQ );
new String:IPnum[30] = "NULL";
SQL_FetchString( LocNumberQ, 0, IPnum, 30 );
CloseHandle( LocNumberQ );
PrintToChat( client, "[SQlite] Ip Number : %s", IPnum );
But that returns
[SQlite] Ip Number : -1737906334

Yours
N3wton

Last edited by n3wton; 04-13-2010 at 19:52.
n3wton is offline
FaTony
Veteran Member
Join Date: Aug 2008
Old 04-13-2010 , 21:15   Re: Error in simple multiplication
Reply With Quote #17

Why would initialise a string to "NULL"? That would be a definite memory leak in C++. God bless SourcePawn's simplicity. On the other note, i'm confised, that code should work as you don't touch integers... Check your SQLite settings.

Last edited by FaTony; 04-13-2010 at 21:18.
FaTony is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-14-2010 , 02:59   Re: Error in simple multiplication
Reply With Quote #18

I just tried "SELECT 16777216 * 16777216" in the SQLite console app, and it gave me the correct result. As far as I can see, there's no reason for your code not to work.
__________________
Scone is offline
n3wton
Senior Member
Join Date: Mar 2010
Old 04-14-2010 , 04:34   Re: Error in simple multiplication
Reply With Quote #19

Ok... this is really wierd, I fiqured there was lots going on when I did the query, so I'd right a new plugin that just did 1 query, and still no luck... Infact, if the query is SELECT 16777216 * 16777216 the result is 0...

Code:
#pragma semicolon 1

#include <sourcemod>
#include <sdktools>

#define CVAR_FLAGS FCVAR_PLUGIN|FCVAR_SPONLY|FCVAR_NOTIFY
#define VERSION "1.0.0"

new Handle:SQliteDB = INVALID_HANDLE;
new bool:SQliteConnected = false;

public Plugin:myinfo =
{
    name = "SQliteErrorExample",
    author = "n3wton",
    description = "Showing the error of multiplication in SQlite",
    version = VERSION
};

public OnPluginStart()
{
    new String:error[64];
    SQliteDB = SQLite_UseDatabase( "sourcemod-local", error, 64 );
    if( SQliteDB != INVALID_HANDLE )
    {
        SQliteConnected = true;
    }
}

public OnClientPostAdminCheck( client )
{
    if( client != 0 && SQliteConnected )
    {
        if( !IsFakeClient(client) )
        {
            new String:Query[256];
            Format( Query, 256, "SELECT 16777216 * 155" );
            new Handle:TableQuery = SQL_Query( SQliteDB, Query );
            if( TableQuery != INVALID_HANDLE )
            {
                new String:Result[20];
                SQL_FetchRow( TableQuery );
                SQL_FetchString( TableQuery, 0, Result, 20 );
                PrintToChat( client, "[SQlite] Query : %s", Query );
                PrintToChat( client, "[SQlite] Result : %s", Result );
            }
        }
    }
}
Thats the code, I was wondering if it would work with SQL databases rather than SQlite, but the thing is SQL databases would be pointless for what i'm using them for...

Yours
N3wton
n3wton is offline
Scone
Senior Member
Join Date: Apr 2010
Location: England
Old 04-14-2010 , 07:20   Re: Error in simple multiplication
Reply With Quote #20

That doesn't make sense, SQLite only uses 64 bit integers - you couldn't limit yourself to 32 bit ones even if you wanted to.

Perhaps SourceMod uses an out-of-date/oddly configured version of SQLite? You'd have more luck using MySQL, as the server is totally separate.
__________________
Scone 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 00:02.


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