Graal Forums  

Go Back   Graal Forums > Development Forums > NPC Scripting
FAQ Members List Calendar Today's Posts

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 11-27-2011, 03:58 AM
Ohk4y Ohk4y is offline
Registered User
Ohk4y's Avatar
Join Date: Jun 2011
Posts: 43
Ohk4y is an unknown quantity at this point
Send a message via AIM to Ohk4y
SQL insert help

Hello, I came across an error while trying to insert a row into a sqlite database, which the database is named 'loot'. I get an error outputted by sql in rc:
PHP Code:
SQL Errorconstraint failed 
Here's the sql part of the script:

PHP Code:
function AddToLoot() {
  
temp.mineral "SELECT content FROM inventories WHERE rowid="@this.itemm;
  
temp.account player.account;
  
temp.classn "mineral";
  
temp.name_en temp.mineral;
  
temp.loc this.level;
  
temp.this.x;
  
temp.this.y;
  
temp.query "INSERT INTO loot (account, class, name_en, loc, x, y) VALUES ('"@temp.account@"', '"@temp.classn@"', '"@temp.name_en@"', '"@temp.loc@"', '"@temp.x@"', '"@temp.y@"')";
  
temp.requestObject requestsql(temp.querytrue);
    
  
this.waitfor(temp.requestObject"onReceiveData"30);
  
  if (
temp.requestObject.error) {
    echo(
"SQL Error: " temp.requestObject.error);
    return;
  }  
  
this.chat temp.requestObject.lastinsertid;

Anybody know what I did wrong?
__________________
Reply With Quote
  #2  
Old 11-27-2011, 03:59 AM
cbk1994 cbk1994 is offline
the fake one
cbk1994's Avatar
Join Date: Mar 2003
Location: San Francisco
Posts: 10,718
cbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond reputecbk1994 has a reputation beyond repute
Send a message via AIM to cbk1994
Not possible to tell without seeing the table structure but I'd guess you're trying to insert a duplicate value into a column with a UNIQUE constraint/index.
__________________
Reply With Quote
  #3  
Old 11-27-2011, 04:02 AM
Ohk4y Ohk4y is offline
Registered User
Ohk4y's Avatar
Join Date: Jun 2011
Posts: 43
Ohk4y is an unknown quantity at this point
Send a message via AIM to Ohk4y
That first row, I just typed in the information manually to see what it would look like.


Don't know if this helps:
PHP Code:
CREATE TABLE 'loot' (account TEXT DEFAULT '' PRIMARY KEY, class TEXT DEFAULT ''name_en TEXT DEFAULT ''loc TEXT DEFAULT ''x INTEGER DEFAULT 0y INTEGER DEFAULT 0
__________________
Reply With Quote
  #4  
Old 11-27-2011, 04:21 AM
fowlplay4 fowlplay4 is offline
team canada
fowlplay4's Avatar
Join Date: Jul 2004
Location: Canada
Posts: 5,200
fowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond reputefowlplay4 has a reputation beyond repute
It's because you have account as your primary key, which automatically makes it unique.
__________________
Quote:
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 +2. The time now is 05:28 PM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Copyright (C) 1998-2019 Toonslab All Rights Reserved.