Graal Forums

Graal Forums (https://forums.graalonline.com/forums/index.php)
-   NPC Scripting (https://forums.graalonline.com/forums/forumdisplay.php?f=8)
-   -   SQL insert help (https://forums.graalonline.com/forums/showthread.php?t=134265117)

Ohk4y 11-27-2011 03:58 AM

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 Error: constraint 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.x = this.x;
  
temp.y = 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.query, true);
    
  
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?

cbk1994 11-27-2011 03:59 AM

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.

Ohk4y 11-27-2011 04:02 AM

That first row, I just typed in the information manually to see what it would look like.
http://img845.imageshack.us/img845/1...gggggggggg.png

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 0, y INTEGER DEFAULT 0) 


fowlplay4 11-27-2011 04:21 AM

It's because you have account as your primary key, which automatically makes it unique.


All times are GMT +2. The time now is 02:26 AM.

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