Go Back   EQEmulator Home > EQEmulator Forums > Archives > Archive::Development > Archive::Development

Archive::Development Archive area for Development's posts that were moved here after an inactivity period of 90 days.

Reply
 
Thread Tools Display Modes
  #1  
Old 01-04-2003, 11:51 AM
Kaiyodo
Hill Giant
 
Join Date: Jan 2002
Location: Midlands,UK
Posts: 149
Default Quick MySQL question

I'm trying to write out an SQL text file from my item editor which anyone can source into their database. The problem I've got is that MySQL seems to want me to use two different methods depending on whether the item already exists or not.

If the item doesn't exist I do this ..

INSERT INTO items VALUES (blah blah ..

If it already exists then I do this ..

UPDATE items SET raw_data = '%s' WHERE id = '%d'

Is there a way to combine these two into a 'catch-all' statement? I can write out different entries based on what exists and what doesn't in my database, but that's no use to any one else.

My best guess so far was to write out two lines for each item like this ..

INSERT IGNORE INTO items VALUES (%d,'%s');
UPDATE items SET raw_data = '%s' WHERE id = %d;

The first line will be ignored if the item exists and then the second line will update the existing item. If the item doesn't exist then it gets inserted and then updated again. This looks nasty, anyone know if there's a nicer way?

Thanks.
K.
Reply With Quote
  #2  
Old 01-04-2003, 01:27 PM
Bob98112
Fire Beetle
 
Join Date: Nov 2002
Posts: 21
Default

What about adding the statement to truncate the table first? It removes the rows (data) and leaves the tabledef intact. At that point, they can all be inserts.

HTH

BoB
Reply With Quote
  #3  
Old 01-04-2003, 01:30 PM
Lurker_005
Demi-God
 
Join Date: Jan 2002
Location: Tourist town USA
Posts: 1,671
Default

I was going to say use a delete before the insert to make it cleaner, but it turns out REPLACE is the command you really want. It is probably the right command to use a lot of other times too, like adding/updating items...


REPLACE INTO items VALUES (%d,'%s');

A little more verbose, but it is suggested to name the columns, just incase the table changes.

REPLACE INTO items (id,raw_data) VALUES (%d,'%s');
__________________
Please read the forum rules and look at reacent messages before posting.
Reply With Quote
  #4  
Old 01-05-2003, 04:58 AM
Kaiyodo
Hill Giant
 
Join Date: Jan 2002
Location: Midlands,UK
Posts: 149
Default

Thanks Lurker, that was exactly what I was looking for.

K.
Reply With Quote
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 05:22 AM.


 

Everquest is a registered trademark of Daybreak Game Company LLC.
EQEmulator is not associated or affiliated in any way with Daybreak Game Company LLC.
Except where otherwise noted, this site is licensed under a Creative Commons License.
       
Powered by vBulletin®, Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Template by Bluepearl Design and vBulletin Templates - Ver3.3