PDA

View Full Version : How to insert large amount of data to sql table?


Dolke
10/04/2019, 12:37 PM
Hello.

I have one problem.How can I save a lot of data in sql table with INSERT? I need to insert about 50 columns in table when player is registered to server.

JesterlJoker
10/04/2019, 12:49 PM
using transactions

Gforcez
10/04/2019, 01:11 PM
Hello.

I have one problem.How can I save a lot of data in sql table with INSERT? I need to insert about 50 columns in table when player is registered to server.

Maybe start by looking what you're inserting. Maybe there's a better solution on a database level. What are you inserting when a player registers?

Logic_
10/04/2019, 01:15 PM
50 fucking what? You really need to do your database organization and normalization if you've so much fields to put data for.

An example would be such as weapons data that is often saved in the players table should be saved separately, the houses and businesses should be loaded from their own table regardless if it's purchased or not by the player, etc.

You should show us the table so we can help you out :)

Dolke
10/04/2019, 05:20 PM
Here is the code for create table.I created table with DB Browser for SQLite and I want to save all of these when player registers (insert in table with values)

https://pastebin.com/98F8v1nT

Dolke
12/04/2019, 06:33 PM
BUMP !

khRamin78
12/04/2019, 07:55 PM
try to optimize your sql database !
see this (https://forum.sa-mp.com/showthread.php?t=505081) method

if all is ok then you need to send big query to your database i think there wont be any problems using high string characters to sql server use like string[2048];
and you have to use << \ >> in while to avoid compiler error in pawno just like this sample code


mysql_format(Handel,query,sizeof(query),"UPDATE accounts SET \
Bsqlid = %d,Hsqlid = %d,Rentsqlid = %d,LastLogin = '%s',\
Vehicle1 = %d,Vehicle2 = %d,Wanted = %d,Food = %f,Water = %f,\
Score = %d,Money = %d,BankMoney = %d,Ecash = %d,ProIncome = %d,\
etc

BlackBank
12/04/2019, 08:55 PM
Why you don't set a default value for all the columns you don't need to INSERT data for? Like for example 'admin', it can be default 0 when a player registers, and so there are more fields.

Gforcez
12/04/2019, 09:37 PM
Why you don't set a default value for all the columns you don't need to INSERT data for? Like for example 'admin', it can be default 0 when a player registers, and so there are more fields.

This is your solution right here. The values you want to set and doesn't have a default value (username, password and what more) you can just add in the INSERT statement.

khRamin78
13/04/2019, 02:25 AM
Why you don't set a default value for all the columns you don't need to INSERT data for? Like for example 'admin', it can be default 0 when a player registers, and so there are more fields.

This is your solution right here. The values you want to set and doesn't have a default value (username, password and what more) you can just add in the INSERT statement.

anyway he should use large query when saving player global data with that amount of data

Dolke
16/04/2019, 05:04 AM
Okay I did it with default values and it works as expected but now how can I save and load player data?

AmirSavand
16/04/2019, 05:12 AM
Search for it, search for saving and loading systems, ton of examples and tutorials.

Dolke
16/04/2019, 11:40 AM
Yes I know how to save player with sqlite but if I need to save just small amount of data,but I do not know how to save large amount of data in UPDATE query

BlackBank
16/04/2019, 09:47 PM
Yes I know how to save player with sqlite but if I need to save just small amount of data,but I do not know how to save large amount of data in UPDATE query

Why you need to save all data at once, if you are already saving small amount of data (when money changed etc)?