Bitcoin Forum
December 06, 2021, 06:30:35 PM *
News: Latest Bitcoin Core release: 22.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Best way to store bitcoin values in MySql?  (Read 1538 times)
KaozTiposta
Full Member
***
Offline Offline

Activity: 253
Merit: 101


View Profile
June 25, 2015, 09:24:39 PM
 #1

Hello

I am developing a bitcoin application using Mysql.

What is the best way to store it? DECIMAL(16,8) or multiplying it with 100M?

1638815435
Hero Member
*
Offline Offline

Posts: 1638815435

View Profile Personal Message (Offline)

Ignore
1638815435
Reply with quote  #2

1638815435
Report to moderator
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction. Advertise here.
1638815435
Hero Member
*
Offline Offline

Posts: 1638815435

View Profile Personal Message (Offline)

Ignore
1638815435
Reply with quote  #2

1638815435
Report to moderator
1638815435
Hero Member
*
Offline Offline

Posts: 1638815435

View Profile Personal Message (Offline)

Ignore
1638815435
Reply with quote  #2

1638815435
Report to moderator
1638815435
Hero Member
*
Offline Offline

Posts: 1638815435

View Profile Personal Message (Offline)

Ignore
1638815435
Reply with quote  #2

1638815435
Report to moderator
secrethedgehog
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 25, 2015, 09:39:05 PM
 #2

A few clients I have worked with store it as VARCHAR, I am no expert but I don't believe that VARCHAR is correct way to store a decimal number.

Personally I would store it as Satoshi BIGINT and then multiply using the language that pulls the data out.
KaozTiposta
Full Member
***
Offline Offline

Activity: 253
Merit: 101


View Profile
June 25, 2015, 09:41:30 PM
 #3

I'm so lazy to multiply/divide it everywhere.. Also VARCHAR sounds interesting to me.

So I think I will go with DECIMAL but this is a little sensitive project and I don't want to see round errors. Can DECIMAL has rounding errors ?
secrethedgehog
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 25, 2015, 09:51:00 PM
 #4

What language are you using to pull the data?

I usually just create one function to multiply and format. Then I can just use that on whatever needs it.

I don't ever use Decimal in MySQL so I don't really know to be honest.

I was only using VARCHAR as a bad example. I wouldn't suggest this. It has caused me some problems in the past.

http://stackoverflow.com/questions/3008371/storing-numbers-as-varchar
person
Sr. Member
****
Offline Offline

Activity: 315
Merit: 250



View Profile WWW
June 25, 2015, 09:56:41 PM
 #5

Store as satoshis: BIGINT
Manipulate as satoshis

Then you can convert in any type (BTC, mBTC) based on user preference only for display.
aysha9859
Member
**
Offline Offline

Activity: 93
Merit: 10

Srry 4 my bad English


View Profile
June 26, 2015, 09:53:24 AM
 #6

Store as satoshis: BIGINT
Manipulate as satoshis

Then you can convert in any type (BTC, mBTC) based on user preference only for display.
im using BIGINT on my faucet project. you can play however you want with satoshi. but sometimes im getting errors. for ex: i have 50000 in the cell. divide 100000000 i get output like 0.00049999 for solve this error im writing convert function. im still working on it.
bitnanigans
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
June 26, 2015, 12:57:27 PM
 #7

You can use either DECIMAL(16,8) or BIGINT.
If you're storing with BIGINT, you will have to make sure that you convert your values correctly at all times, or you may run into several problems.
The decimal is used for precision math, so you won't encounter rounding errors with the data type.
person
Sr. Member
****
Offline Offline

Activity: 315
Merit: 250



View Profile WWW
June 26, 2015, 02:35:56 PM
 #8

Store as satoshis: BIGINT
Manipulate as satoshis

Then you can convert in any type (BTC, mBTC) based on user preference only for display.
im using BIGINT on my faucet project. you can play however you want with satoshi. but sometimes im getting errors. for ex: i have 50000 in the cell. divide 100000000 i get output like 0.00049999 for solve this error im writing convert function. im still working on it.

For display, why divide if you can just add the . after 8 characters (as string)?
wh00per
Hero Member
*****
Offline Offline

Activity: 570
Merit: 500



View Profile
June 27, 2015, 05:59:55 PM
 #9

What's wrong with double? The precison is way better than what you need for satoshi transactions.

https://dev.mysql.com/doc/refman/5.0/en/fixed-point-types.html

You can also do BIGINT as satoshi, or varchar, however while bigint indexes nicely and it's quick, varchar is a little laggy.  

As of 5.0.6, MySQL performs DECIMAL (or NUMERIC) operations with a precision of 65 decimal digits. If you need exact values in your applications I'd rather use one of those two.

CSA/cUL Certified Power Distribution Panels - Basic, Switched, Metered. 1-3 phases. Up to 600V. NMC:N4F9qvHz11BHcc4nh1LCJFsrZhA1EWgVwj
Vortex20000
Hero Member
*****
Offline Offline

Activity: 504
Merit: 500

sucker got hacked and screwed --Toad


View Profile WWW
June 28, 2015, 02:11:12 PM
 #10

Just use MySQL's double type, it's what I use and I've had any problems with it thus far.

bitnanigans
Sr. Member
****
Offline Offline

Activity: 266
Merit: 250


View Profile
June 28, 2015, 02:36:03 PM
 #11

Just use MySQL's double type, it's what I use and I've had any problems with it thus far.

This is a very wrong approach. See http://stackoverflow.com/questions/2251290/storing-money-amounts-in-mysql
THE TRADER
Newbie
*
Offline Offline

Activity: 16
Merit: 0


View Profile
June 28, 2015, 03:06:50 PM
 #12

Be Carefull ob un Mysql Injections. https://de.wikipedia.org/wiki/SQL-Injection

It`s maybe not actually the Securityst Technologie. Scrypt.cc got hacked by mysql injection. And used a got based on mysql/ddos page so far.

My opion but im not a Profi  Grin
secrethedgehog
Newbie
*
Offline Offline

Activity: 50
Merit: 0


View Profile
June 28, 2015, 04:26:21 PM
 #13

Be Carefull ob un Mysql Injections. https://de.wikipedia.org/wiki/SQL-Injection

It`s maybe not actually the Securityst Technologie. Scrypt.cc got hacked by mysql injection. And used a got based on mysql/ddos page so far.

My opion but im not a Profi  Grin

There are many techniques to stop this, You shouldn't be scared of using MySql, You should be scared of how good your coding is.... or not.

In PHP there are techniques like Prepared Statements and escaping characters.
noel57
Sr. Member
****
Offline Offline

Activity: 392
Merit: 250



View Profile
June 29, 2015, 05:31:51 AM
 #14

Hello

I am developing a bitcoin application using Mysql.

What is the best way to store it? DECIMAL(16,8) or multiplying it with 100M?


Keep it simply simple, 8 digits still remain the best, any other extension will be boring and some-how confusing.

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!