Saturday, April 7, 2012

Import csv file to MySql Database

Recently looking for ways to Import data from csv file to MySql database. Mysql  database has powerful feature that allows user to import csv file directly to database. Sample code shows below:

create table statement:
DROP TABLE IF EXISTS `share_market`.`klse`;
CREATE TABLE  `share_market`.`klse` (
  `dates` date DEFAULT NULL,
  `opens` decimal(10,4) DEFAULT '0.0000',
  `highs` decimal(10,4) DEFAULT '0.0000',
  `lows` decimal(10,4) DEFAULT '0.0000',
  `closes` decimal(10,4) DEFAULT '0.0000',
  `volumn` decimal(20,4) DEFAULT '0.0000'

command to import csv file:
LOAD DATA LOCAL INFILE 'd:\klci analysis.csv'
into table klse
(dates, opens, highs,lows,closes, volumn);

where table name is "klse", field name is "dates", "opens", "highs","lows","closes" and  "volumn"
Use "s" for each field to avoid reserve word "open" and "close"

Tuesday, April 3, 2012

Float, Double and Decimal

There are many ways to store number value. Let’s pick three variable types of numbers that we always use: float, double and decimal. What are those differences?

decimal dd = 1234567890.123456789712345678971234567897M;

            double db = Convert.ToDouble(dd) * 1;
            float fl = (float)dd * 1;
            decimal dc = dd * 1;
            txtdecimal.Text = dc.ToString("f20");
            txtdouble.Text = db.ToString("f20");
            txtfloat.Text = fl.ToString("f20");


1. float able to store 7 digit precision
2. double can store 16 digit precision
3. decimal can store up to 27 digit precision -> this is a surprise. even decimal can be out of range with less then 30 digit precision!

Currently I am researching on OpenCL and OpenCL allows ONLY double and float variable. Therefore graphic card is not suitable for task that requires high precision. OpenCL is more suitable for simulation or mass calculation like CAD CAM tools. Will update more information on OpenCL + c# when research is done.