Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to handle a huge string correctly?

Tags:

c

windows

This may be a newbie question, but i want to avoid buffer overflow. I read very much data from the registry which will be uploaded to an SQL database. I read the data in a loop, and the data was inserted after each loop. My problem is, that this way, if i read 20 keys, and the values under is ( the number of keys is different on every computer ), then i have to connect to the SQL database 20 times.

However i found out, that there is a way, to create a stored procedure, and pass the whole data it, and so, the SQL server will deal with data, and i have to connect only once to the SQL server.

Unfortunately i don't know how to handle such a big string to avoid any unexpected errors, like buffer owerflow. So my question is how should i declare this string?

Should i just make a string like char string[ 15000 ]; and concatenate the values? Or is there a simplier way for doing this?

Thanks!

like image 382
kampi Avatar asked Nov 05 '22 13:11

kampi


1 Answers

STL strings should do a much better job than the approach you have described.

You'll also need to build some thresholds. For example, if your string grew more than a mega bytes, it will be worth considering making different SQL connections since your transaction will be too long.

like image 137
Peon the Great Avatar answered Nov 15 '22 04:11

Peon the Great