View Single Post
  #12  
Old 06-09-2010, 08:46 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
Quote:
Originally Posted by xAndrewx View Post
If you are using SQL like that, isn't it laggy? (With alot of players...?)
It depends a lot more on how you structure your system than the limits of SQL.

A quick example:

PHP Code:
function r(str) {
  echo(
"+" @ (timevar2 this.start) @ ": " str);
}

function 
onCreated() {
  
this.join("func_sql");
  
  
req("DROP TABLE IF EXISTS test_2");
  
  
// this only has to be done once
  
sqliteEnableFileSynchronization("default"false);
  
this.start timevar2;
  
  
// begin transaction
  
  
r("Beginning transaction");
  
req("BEGIN");
  
  
r("Creating table");
  
req("CREATE TABLE IF NOT EXISTS test_2 (account TEXT NOT NULL DEFAULT '', itemid TEXT NOT NULL DEFAULT '', quantity INT NOT NULL DEFAULT 0)");
  
  
r("Creating index");
  
req("CREATE INDEX IF NOT EXISTS idx_test ON test_2 (account, itemid)");
  
  
temp.items = {"uzi""handgun""shotgun""ak47""medpack""skateboard""ammo"};
  
  
r("Adding 70,000 rows to table");
  
temp.0;
  
  
// add 70,000 rows to the table
  
for (temp.item items) {
    for (
temp.010000++) {
      
req("INSERT INTO test_2 (account, itemid, quantity) VALUES ('" "', '" item "', " int(random(11000)) @ ")");
      
      if (
this.maxlooplimit == 0) {
        
sleep(0.1); // avoid max loop limit
      
}
      
      
++;
    }
  }
  
  
r("Done adding items");
  
req("COMMIT");
  
r("Transaction closed");
  
  
// reset time
  
echo("--time reset--");
  
this.start timevar2;
  
  
temp.num req("SELECT sum(quantity) FROM test_2 WHERE itemid = 'ak47'"true)[0][0];
  
r("Total number of AK47s: " num);
  
  
temp.num req("SELECT * FROM test_2 WHERE itemid = 'ak47' AND account = '2653'"true)[0].quantity;
  
r("How many AK47s account '2653' has: " num);
  
  
req("UPDATE test_2 SET quantity = quantity + 200 WHERE account = '2653' AND itemid = 'ak47'");
  
r("Added 200 AK47s to account '2653'");
  
  
temp.num req("SELECT * FROM test_2 WHERE itemid = 'ak47' AND account = '2653'"true)[0].quantity;
  
r("How many AK47s account '2653' has: " num); 
outputs:

Quote:
+0: Beginning transaction
+0.000104904: Creating table [0.0001 seconds]
+0.000465869: Creating index [0.0003 seconds]
+0.000668048: Adding 70,000 rows to table [0.0002 seconds]
+4.176818847: Done adding items [4.18 seconds]
+4.183884859: Transaction closed [0.01 seconds]
--time reset--
+0.035701036: Total number of AK47s: 4971411 [0.04 seconds]
+0.035872936: How many AK47s account '2653' has: 380 [0.0001 seconds]
+0.036087036: Added 200 AK47s to account '2653' [0.001 seconds]
+0.03618288: How many AK47s account '2653' has: 580 [0.0001 seconds]
SQLite is no pushover .
__________________
Reply With Quote