INTEGER PRIMARY KEY AUTOINCREMENT , Some help...
#1

Hi, i have a small question about INTEGER PRIMARY KEY AUTOINCREMENT in SQLite.

So first step:
I make a simple database:
Code:
db_query( Database, "CREATE TABLE IF NOT EXISTS `Database` ( `Key` INTEGER PRIMARY KEY AUTOINCREMENT, `Name` TEXT, `Numbers` NUMERIC )" );
Ok, i make 3 accounts ... in database will be show like this:
Code:
Key | Name | Numbers |
1              | Edvin           |  1022              |
2              | Edvin2         |  1010              |
3              | Edvin3         |  9000              |
Now i don't know how to do. When a player delete his account with "Key" 1 , account name "Edvin", the rest of account to move on -1 "Key", and in database will show something like this:
Code:
Key | Name | Numbers |
1              | Edvin2         |  1010              |
2              | Edvin3         |  9000              |
To don't stay in this position, after i delete an account:
Code:
Key | Name | Numbers |
2              | Edvin2         |  1010              |
3              | Edvin3         |  9000              |
... ?
Reply
#2

There isn't really any way you can do this properly. May I ask why you want to do this in the first place?
Reply
#3

Probably so he can delete accounts and not have holes in the numeric value of said accounts...like 1 2 3 4 5 7 8 9 11 12 13 14 16 etc so it would be 1 2 3 4 5 6 7 8 9 10 11 12 13
Reply
#4

I create a clans system in SQLite, when a clan have one member/leader and hi leave the clan, the clan automatic is deleting from database, and here is the bug: if i created the first clan, with "Key" = 1 and after i leave him, the other players can't create more clans because they don't register in database. I am sure this bug si caused by "Key" on clans, because if exists 3 ( Clan1 = Key = 1 | Clan2 = Key = 2 | Clan3 = Key = 3 ) clans in DB and i leave the first with "Key" = 1 on other 2 clans don't change the "Key" in database 8-| ... and this thing i don't know how to do ...
Reply
#5

Your syntax is incorrect, try this:

PHP Code:
mysql_query("CREATE TABLE users (Key int NOT NULL AUTO_INCREMENT, PRIMARY KEY(Key))"); 
EDIT: Whoops sorry didn't see it was SQLite :/
Reply
#6

No, i need to modify command /lclan( leave clan ), to existent clans move on -1 keys everyone

PS. Here is the /lclan command:
Code:
CMD:lclan(playerid,params[])
{
    register(playerid);
    db:Query(xFM("UPDATE `gangs` SET `members` = `members`-1 WHERE `id`='%d'",gang[playerid][ID]));
	db:Query(xFM("UPDATE `players` SET `gang`='NULL' WHERE `name`='%s'",name));
	new DBResult:R;
	R = db:Query(xFM("SELECT * FROM `gangs` WHERE `id`='%d'",gang[playerid][ID]));
	db_get_field_assoc(R,"members",str,sizeof(str));
	db_free_result®;
	if(strval(str)==0)
	{
	    db:Query(xFM("DELETE FROM `gangs` WHERE `id`='%d'",gang[playerid][ID]));
	}
	format(str, sizeof(str), "CLAN: {F6358A}Jucatorul {FF0000}%s{F6358A} a parasit gasca sau a fost scos de catre leader!", name);
	for(new i;i<MAX_PLAYERS;i++)
	{
	    if(IsPlayerConnected(i)&& gang[i][ID]==gang[playerid][ID])
	    {
	        SendClientMessage( i, ~0, str );
	    }
	}
	ResetPlayerWeapons(playerid);
	gang[playerid][ID]=0;
	gang[playerid][rank]=0;
	gang[playerid][skin]=0;
	gang[playerid][spawnX]=0.0;
	gang[playerid][spawnY]=0.0;
	gang[playerid][spawnZ]=0.0;
	gang[playerid][spawnA]=0.0;
	gang[playerid][Weap1]=0;
	gang[playerid][Weap2]=0;
	gang[playerid][Weap3]=0;
	gang[playerid][Weap4]=0;
	gang[playerid][Weap5]=0;
	gang[playerid][Weap6]=0;
	gang[playerid][Kills]=0;
	gang[playerid][Deaths]=0;
	SetPlayerHealth( playerid, 0.0 );
	SetPlayerSkin( playerid, 217 );
	SetPlayerColor( playerid, RandomColors[ random( 400 ) ] );
	SendClientMessage( playerid, 0x00FF00FF, "You have left your clan, or you have been kicked by a leader!" );
	return 1;
}
Reply
#7

Show OnPlayerSpawn, OnplayerConnect and command Invite
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)