Maximum SQL Table Fields ?
#1

hello,

so yeah as the title says..

let me explain:

In my table there is 5 fields, no problem right?, the problem starts when I add a new field to them; it doesn't save then,
why? (or it's from my code) ?

PHP код:

    
new Query[128];
    new 
PlayerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridPlayerNameMAX_PLAYER_NAME);
    
format(Query128"INSERT INTO `USERS` (`NAME`, `PASSWORD`, `ADMINLEVEL`, `CASH`, `SCORE`) VALUES ('%s','%s','0','0','0')"DB_Escape(PlayerName), DB_Escape(inputtext));
    
db_query(DataBaseQuery); 
This one above saves.

PHP код:

    
new Query[128];
    new 
PlayerName[MAX_PLAYER_NAME];
    
GetPlayerName(playeridPlayerNameMAX_PLAYER_NAME);
    
format(Query128"INSERT INTO `USERS` (`NAME`, `PASSWORD`, `ADMINLEVEL`, `CASH`, `SCORE`, `SKIN`) VALUES ('%s','%s','0','0','0', '0')"DB_Escape(PlayerName), DB_Escape(inputtext));
    
db_query(DataBaseQuery); 
This one ^^, doesn't but why?

any help will be appreciated!!
~Thanks~
Reply
#2

You need to use the "ALTER TABLE `table_name` ADD COLUMN `column_name` type" statement to add new fields you cant just insert values and the fields be created.

pawn Код:
ALTER TABLE users ADD COLUMN admin_level INT
EDIT: To answer your question 2000 columns is the default max amount of columns for an SQLite DB. (for the newest version of SQLite not sure which one sa-mp uses).

Source: http://www.sqlite.org/draft/limits.html
Reply
#3

Quote:
Originally Posted by iggy1
Посмотреть сообщение
You need to use the "ALTER TABLE `table_name` ADD COLUMN `column_name` type" statement to add new fields you cant just insert values and the fields be created.

pawn Код:
ALTER TABLE users ADD COLUMN admin_level INT
EDIT: To answer your question 2000 columns is the default max amount of columns for an SQLite DB. (for the newest version of SQLite not sure which one sa-mp uses).

Source: http://www.sqlite.org/draft/limits.html
okay thanks, but what if I need to add a new column? in the same way?

Quote:
Originally Posted by ******
Посмотреть сообщение
Probably because you did something else wrong like not setting up the table correctly. Databases are designed to handle TERABYTES of data in vastly complex arrangements, if it can't hack your six fields you did something wrong.
but how it's wrong, if the 5 fields are working perfect?, the 6 field is only "duplicated" to the ones before it...
Reply
#4

You said your database has 5 fields? I'm guessing NAME PASSWORD ADMINLEVEL CASH SCORE.

So if that's the case, before you run the second query you need to alter the database and add the new columns (SKIN).

pawn Код:
ALTER TABLE `USERS` ADD COLUMN `SKIN` INT
After running that query it should be fine to insert into the SKIN column because it now exists.
Reply
#5

Quote:
Originally Posted by iggy1
Посмотреть сообщение
You said your database has 5 fields? I'm guessing NAME PASSWORD ADMINLEVEL CASH SCORE.

So if that's the case, before you run the second query you need to alter the database and add the new columns (SKIN).

pawn Код:
ALTER TABLE `USERS` ADD COLUMN `SKIN` INT
After running that query it should be fine to insert into the SKIN column because it now exists.
alright thanks but I got one more question, do I use the same system of loading and saving in this additional columns?
Reply
#6

As long as you select the data correctly you should be fine. Once you have inserted a new column just add it to your SELECT/UPDATE queries like any column.

You only have to add the column once then you can remove it from your code. (the ALTER TABLE statement that is)
Reply
#7

Quote:
Originally Posted by iggy1
Посмотреть сообщение
As long as you select the data correctly you should be fine. Once you have inserted a new column just add it to your SELECT/UPDATE queries like any column.

You only have to add the column once then you can remove it from your code. (the ALTER TABLE statement that is)
Oka-ay, Thanks, and thanks a lot for this beautiful article, yeah it made me understands a lot and again thanks!
Reply
#8

You need to increase the size of the query string from 128 to something bigger so it can fit everything into the string.
Reply
#9

Quote:
Originally Posted by SuperViper
Посмотреть сообщение
You need to increase the size of the query string from 128 to something bigger so it can fit everything into the string.
Lol, such a simple fix.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)