Author

Topic: Best way to store bitcoin values in MySql? (Read 1567 times)

sr. member
Activity: 392
Merit: 250
June 29, 2015, 12: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.
newbie
Activity: 50
Merit: 0
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.
newbie
Activity: 16
Merit: 0
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
sr. member
Activity: 266
Merit: 250
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
hero member
Activity: 504
Merit: 500
sucker got hacked and screwed --Toad
Just use MySQL's double type, it's what I use and I've had any problems with it thus far.
hero member
Activity: 572
Merit: 500
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.
sr. member
Activity: 315
Merit: 250
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)?
sr. member
Activity: 266
Merit: 250
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.
member
Activity: 93
Merit: 10
Srry 4 my bad English
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.
sr. member
Activity: 315
Merit: 250
Store as satoshis: BIGINT
Manipulate as satoshis

Then you can convert in any type (BTC, mBTC) based on user preference only for display.
newbie
Activity: 50
Merit: 0
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
full member
Activity: 244
Merit: 101
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 ?
newbie
Activity: 50
Merit: 0
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.
full member
Activity: 244
Merit: 101
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?

Jump to: