AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   SQL Selecting a Row? (https://forums.alliedmods.net/showthread.php?t=82643)

Drak 12-27-2008 03:10

SQL Selecting a Row?
 
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.

danielkza 12-27-2008 03:19

Re: SQL Selecting a Row?
 
Quote:

Originally Posted by Drak (Post 733857)
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 Float:Distance = 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'.

Drak 12-27-2008 05:25

Re: SQL Selecting a Row?
 
Quote:

Originally Posted by danielkza (Post 733859)
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.

|PJ| Shorty 12-27-2008 08:04

Re: SQL Selecting a Row?
 
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 :wink:

danielkza 12-27-2008 10:01

Re: SQL Selecting a Row?
 
Quote:

Originally Posted by Drak (Post 733891)
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.

Hawk552 12-28-2008 20:00

Re: SQL Selecting a Row?
 
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.

Drak 12-29-2008 03:09

Re: SQL Selecting a Row?
 
Quote:

Originally Posted by Hawk552 (Post 734678)
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 >= #

Hawk552 12-29-2008 03:50

Re: SQL Selecting a Row?
 
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.


All times are GMT -4. The time now is 09:18.

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