Register for your free account! | Forgot your password?

Go Back   elitepvpers > MMORPGs > Flyff > Flyff Private Server
You last visited: Today at 05:44

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Question about Database Varchar vs Int

Discussion on Question about Database Varchar vs Int within the Flyff Private Server forum part of the Flyff category.

Reply
 
Old   #1
 
elite*gold: 0
Join Date: Jul 2016
Posts: 230
Received Thanks: 7
Question about Database Varchar vs Int

I would like to ask about database here.

Let's just say i've added a datatype in DBManager in the source which is
SQL_PARAM_INPUT, SQL_C_LONG, SQL_VARCHAR

and i wrote a datatype INT in my Character_TBL

Is there gonna be a problem about the saving of data?
elitemember21 is offline  
Old 09/22/2018, 15:49   #2
 
elite*gold: 0
Join Date: Sep 2018
Posts: 14
Received Thanks: 1
VARCHAR can hold number(INT) so its ok. but it's better to parse the data to INT before saving to make sure that it will not save as string.
theo4595 is offline  
Thanks
1 User
Old 09/25/2018, 12:45   #3
 
xTwiLightx's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,739
Received Thanks: 1,669
Quote:
Originally Posted by elitemember21 View Post
I would like to ask about database here.

Let's just say i've added a datatype in DBManager in the source which is
SQL_PARAM_INPUT, SQL_C_LONG, SQL_VARCHAR

and i wrote a datatype INT in my Character_TBL

Is there gonna be a problem about the saving of data?
Of course there will be a problem or at least undefined behaviour can occur.


value2 works because SQL Server can interpret parts of the string as a number (which depends on how long that varchar is defined), but as soon as I would define it as 'varchar(4)', it won't work anymore, because it had to parse the 'a', which is not an integer.
Same goes for value3.

As long as your input is just numeric/integer, that could work out well. But you want your application to be consistent, so your types should be consistent too.

So: Better use 'SQL_INTEGER' or 'SQL_BIGINT' for the parameter binding to ensure your data is put into the database as intended.
xTwiLightx is offline  
Thanks
1 User
Old 09/25/2018, 14:51   #4
 
elite*gold: 0
Join Date: Jul 2016
Posts: 230
Received Thanks: 7
Quote:
Originally Posted by xTwiLightx View Post
Of course there will be a problem or at least undefined behaviour can occur.


value2 works because SQL Server can interpret parts of the string as a number (which depends on how long that varchar is defined), but as soon as I would define it as 'varchar(4)', it won't work anymore, because it had to parse the 'a', which is not an integer.
Same goes for value3.

As long as your input is just numeric/integer, that could work out well. But you want your application to be consistent, so your types should be consistent too.

So: Better use 'SQL_INTEGER' or 'SQL_BIGINT' for the parameter binding to ensure your data is put into the database as intended.
Thank you very much for this. This helps me understand the database and source more.
elitemember21 is offline  
Old 09/26/2018, 01:37   #5
 
xTwiLightx's Avatar
 
elite*gold: 0
Join Date: Jan 2009
Posts: 1,739
Received Thanks: 1,669
Quote:
Originally Posted by elitemember21 View Post
Thank you very much for this. This helps me understand the database and source more.
No problem. This is more a database related topic.

Your query could also fail because of the parameter binding itself (which is not the direct execution of statements, but preperation [see Prepared statements] in favor of performance, consistency and - more importantly - security [SQL Injection]). ODBC and other database interfaces can retrieve some errors from the underlying DBMS and redirect that information to the application even before a 'select', 'insert' or something else will be exectuted - which in Flyff's case would be a CQuery-Logfile entry. :P
xTwiLightx is offline  
Thanks
1 User
Old 09/27/2018, 12:09   #6
 
elite*gold: 0
Join Date: Jul 2016
Posts: 230
Received Thanks: 7
Very well said and very informative. Thanks a lot.
elitemember21 is offline  
Thanks
1 User
Reply


Similar Threads Similar Threads
[FIX] SQL Error to convert Varchar in Datetime
04/12/2016 - Shaiya PServer Guides & Releases - 13 Replies
Hi many guys asked me why they were getting in their log, the SQL error: error to convert "Varchar in Datetime", so i took a look on EPvPers and i didn't see (maybe i'm wrong o.o) any post with the problem solved. It happens with Warehouse dcing when trying to store items or the notice board ! It's not really a Fix but more a specific attention to pay on SQL configurations. SQL maybe tried to save the datas in a wrong date format ! To check if you're in this case, run the next query:
Varchar to datetime error
06/19/2013 - Shaiya PServer Development - 5 Replies
Hi, everyone... to the point.... I'm having some problems with mi warehouse and item mall, all the problems are because varchar cannot convert into datetime (I THINK) and I'm getting sick of searching in others post because anything works :( so... here are my logs. Hope somebody could help me... please please :handsdown: If somebody knows how to fix this, I'll be grateful if he explains me detailed and sloooooooowly please :p PS_GAME__system log start (Game01) 2013-06-18 22:30:05...



All times are GMT +2. The time now is 05:44.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.