Raised This Month: $ Target: $400
 0% 

SQL Selecting a Row?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Drak
Veteran Member
Join Date: Jul 2005
Old 12-27-2008 , 03:10   SQL Selecting a Row?
Reply With Quote #1

Okay, so, I have this.
Code:
    while(SQL_MoreResults(Query))     {         SQL_ReadResult(Query,0,Origin[0]);         SQL_ReadResult(Query,1,Origin[1]);         SQL_ReadResult(Query,2,Origin[2]);                 new Float:Distance = get_distance_f(Origin,EntOrigin);         if(Distance <= 37.0)         {                        // RIGHT HERE I WANT TO DELETE THIS ROW         }         SQL_NextRow(Query);    } }
Reading the comment, is it possable to get what row it's reading? So i can delete it. SQL_NextRow doesn't return a value, so I have no idea.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 12-27-2008 , 03:19   Re: SQL Selecting a Row?
Reply With Quote #2

Quote:
Originally Posted by Drak View Post
Okay, so, I have this.
Code:
&nbsp;&nbsp;&nbsp;&nbsp;while(SQL_MoreResults(Query)) &nbsp;&nbsp;&nbsp;&nbsp;{ &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;SQL_ReadResult(Query,0,Origin[0]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;SQL_ReadResult(Query,1,Origin[1]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;SQL_ReadResult(Query,2,Origin[2]); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;new Floatistance = get_distance_f(Origin,EntOrigin); &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;if(Distance <= 37.0) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;{ // RIGHT HERE I WANT TO DELETE THIS ROW &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nb sp;} SQL_NextRow(Query); } }

Reading the comment, is it possable to get what row it's reading? So i can delete it. SQL_NextRow doesn't return a value, so I have no idea.
Best way to do this is to add a PRIMARY KEY column for the table, normally using AUTO_INCREMENT, that should represent each row with an unique number. Then you can read it and do 'DELETE FROM table WHERE id=%d LIMIT 1'.
__________________

Community / No support through PM
danielkza is offline
Drak
Veteran Member
Join Date: Jul 2005
Old 12-27-2008 , 05:25   Re: SQL Selecting a Row?
Reply With Quote #3

Quote:
Originally Posted by danielkza View Post
Best way to do this is to add a PRIMARY KEY column for the table, normally using AUTO_INCREMENT, that should represent each row with an unique number. Then you can read it and do 'DELETE FROM table WHERE id=%d LIMIT 1'.
That's the problem, If have a primary key, I'm not allowed duplicate rows am I? Because the table is set up "<Entity Model> <X><Y><Z>" but I have the same entity model in the table. If I set a key, it throws the "duplicate row" error.
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
|PJ| Shorty
Veteran Member
Join Date: Aug 2005
Location: Bavaria, Germany
Old 12-27-2008 , 08:04   Re: SQL Selecting a Row?
Reply With Quote #4

if you want to delete all rows where a value is for example <= 37.0:
Code:
'DELETE FROM table WHERE x<=37.0'
if your PRIMARY KEY is your entity id, read this entity id than you can do:
Code:
'DELETE FROM table WHERE entity_id=%d'
it all depends from your db structure and your SELECT query

you could also set a PRIMARY KEY id AUTO INCREMENT and set your entity_id as UNIQUE

you see, a lot of possible solutions
__________________
There are only 10 types of people in the world:
Those who understand binary, and those who don´t.

Last edited by |PJ| Shorty; 12-27-2008 at 08:20.
|PJ| Shorty is offline
Send a message via ICQ to |PJ| Shorty Send a message via AIM to |PJ| Shorty Send a message via MSN to |PJ| Shorty Send a message via Yahoo to |PJ| Shorty Send a message via Skype™ to |PJ| Shorty
danielkza
AMX Mod X Plugin Approver
Join Date: May 2007
Location: São Paulo - Brasil
Old 12-27-2008 , 10:01   Re: SQL Selecting a Row?
Reply With Quote #5

Quote:
Originally Posted by Drak View Post
That's the problem, If have a primary key, I'm not allowed duplicate rows am I? Because the table is set up "<Entity Model> <X><Y><Z>" but I have the same entity model in the table. If I set a key, it throws the "duplicate row" error.
As I said the primary key just have to indentifiy the rows, it doesn't have to mean anything, just be an unique number.
__________________

Community / No support through PM
danielkza is offline
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 12-28-2008 , 20:00   Re: SQL Selecting a Row?
Reply With Quote #6

You'd have to dispatch a query that read something like:

Code:
DELETE FROM table WHERE originx='%f',originy='%f',originz='%f';
It doesn't seem like you have more information than that to use. There's probably some algorithm that can be written using transactions, but I'm assuming you're running HWRP and thus can't use MySQL 5.0+, so that's out of the question.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
Drak
Veteran Member
Join Date: Jul 2005
Old 12-29-2008 , 03:09   Re: SQL Selecting a Row?
Reply With Quote #7

Quote:
Originally Posted by Hawk552 View Post
You'd have to dispatch a query that read something like:

Code:
DELETE FROM table WHERE originx='%f',originy='%f',originz='%f';
It doesn't seem like you have more information than that to use. There's probably some algorithm that can be written using transactions, but I'm assuming you're running HWRP and thus can't use MySQL 5.0+, so that's out of the question.
HWRP -> ARP.
I only use you, Hawk.

But anyways, this method I tried. But the origins are slightly off. I can't try yet, but as Shorty said. I might just do Origin <= # AND Origin >= #
__________________
Oh yeah
Drak is offline
Send a message via MSN to Drak
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 12-29-2008 , 03:50   Re: SQL Selecting a Row?
Reply With Quote #8

Oh, you can use the data layer then. Look in ApolloRP_Data.inc. It's a wrapper for a keytable that saves itself to SQL. If you need examples, check out ARP_JailMod (included with it) and ARP_Fero (extra plugin I posted on the site). You shouldn't need access to the database for anything other than insanely long entries.
__________________
Hawk552 is offline
Send a message via AIM to Hawk552
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 09:18.


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