Today I required to load a file into a database, the file requires some parsing to be loaded. Normal developer would load the file using a programming language, do the parsing and insert into the table. However, for me, I thought I would do it using MySQL DATA LOAD, it is faster and yet, no programming language required to load the files.
I am posting a sample code on how to parse files line by line using MySQL.
LOAD DATA LOCAL INFILE ‘path/to/my/file’ into table [table-name]
(@line)
set field1 = SUBSTR(@line,1,10),
field2 = SUBSTR(@line, 11,12),
field3 = SUBSTR(@line, 48,19)
Now, what I did, is I just parsed text, since the file was not delimited but it had fixed width.
I have tried Python earlier, but its syntax didn’t make sense to me. Several weeks later, I wanted write a small app, so, I thought, why not try to write it in Python.. Just give it a try… So, I start writing the app in Python, it took longer than it should have, but it was done! Now, I can program in Python. I am so happy that I have finished writing my app in Python. Looks like Python has been added to my portfolio of programming languages.
A new year arrived, and new projects are arriving… My friend Marwan and myself started having several projects to be developed for the Maemo powered devices. However, after discussion today, we have agreed on developing stuff to be cross platform. Most of our development well be in Python GTK.
The agreement is that Marwan will do most of the development, I will be maintaining the projects. I will be responsible of the packaging and bug fixing and some development. Marwan will be doing the core of the applications.
We will be registering a new domain and it will be dedicated for our joint projects. We have lots of ideas, so wish us luck!!
Tags: Ali, Ali Almahdi, Almahdi, gtk, maemo, Marwan, Marwan Alsabbagh, N900, Nokia N900, pygtk, python
Programming | Ali |
January 4, 2010 9:49 pm |
Comments (0)