· 7 years ago · Oct 08, 2018, 01:32 AM
1-- OPTION 1 [ 3 Tables ]
2CREATE TABLE "karma" ("username" VARCHAR PRIMARY KEY NOT NULL , "karma" INTEGER NOT NULL DEFAULT 0, "positive" INTEGER NOT NULL DEFAULT 0, "negative" INTEGER NOT NULL DEFAULT 0)
3-- --
4CREATE TABLE "karma_negative" ("username" VARCHAR NOT NULL ,"contributor" VARCHAR NOT NULL ,"timestamp" DATETIME DEFAULT (current_timestamp) )
5CREATE TABLE "karma_positive" ("username" VARCHAR NOT NULL ,"contributor" VARCHAR NOT NULL ,"timestamp" DATETIME DEFAULT (current_timestamp) )
6-- This way you can enter your own date or it uses default current_timestamp for the current time its added
7INSERT INTO "karma_negative" VALUES ( 'username' , 'contributor' , '2012-08-30 21:17:42' ); -- to add an entry to the negative ones with custom date
8INSERT INTO "karma_negative" VALUES ( 'username' , 'contributor' , (current_timestamp) ); -- to add an entry to the negative ones with 'now'
9-- same is for karma_positive
10-- you should add an 'if not exist' in luxxorz on karma command to be sure the table exists :D
11-- this is what luxxorz should do on kamra entry
12--
13-- on karma command
14-- if exists
15CREATE TABLE IF NOT EXISTS "karma" ("username" VARCHAR PRIMARY KEY NOT NULL , "karma" INTEGER NOT NULL DEFAULT 0, "positive" INTEGER NOT NULL DEFAULT 0, "negative" INTEGER NOT NULL DEFAULT 0)
16-- on karma++
17CREATE TABLE IF NOT EXISTS "karma_positive" ("username" VARCHAR NOT NULL ,"contributor" VARCHAR NOT NULL ,"timestamp" DATETIME DEFAULT (current_timestamp) )
18INSERT INTO "karma_positive" VALUES ( 'username' , 'contributor' , (current_timestamp) )
19UPDATE karma SET "positive" = "positive" + 1 WHERE username = 'username'
20UPDATE karma SET "karma" = "positive" + "negative" WHERE username = 'username'
21-- on karma--
22CREATE TABLE IF NOT EXISTS "karma_negative" ("username" VARCHAR NOT NULL ,"contributor" VARCHAR NOT NULL ,"timestamp" DATETIME DEFAULT (current_timestamp) )
23INSERT INTO "karma_negative" VALUES ( 'username' , 'contributor' , (current_timestamp) )
24UPDATE karma SET "negative" = "negative" + 1 WHERE username = 'username'
25UPDATE karma SET "karma" = "positive" + "negative" WHERE username = 'username'