jeudi 2 juillet 2015

SQLite: How can I insert data from two separate files?

I have two text files that I need to cross reference. One file contains a medium sized (~3000 lines) list with two columns delimited by commas. The second is the same but with different data and roughly 30000 lines. The first file contains a list of Models and Parent Names. The second file is a list of Parent Names and Child Names. I needed a way to cross reference and match file 1 with file 2 without having multiple Child Names. I think SQLite is my best choice because I have the can set the Child Names as unique and the Models and Parent Names can be repeated. I have created a table with 3 columns, one for the Models, one for Parent Names, and the last for Child Names. Now I do not have a way to insert the data from each text file.

Here are examples of the two text files.

File 1 (model, parent):

10101, 2notherbuildsfe
1561, 7_11_door
1560, 7_11_door
14690, 7_11_posters
19327, 7_11_posters
19329, 7_11_posters
14692, 7_11_posters
19328, 7_11_posters
14691, 7_11_posters
14695, 7_11_posters
19326, 7_11_posters
13659, 8bars
13661, 8bars
13628, 8stad
16782, 51_detailstuff
...

File 2 (parent, child):

vg_mun_extars5, 1_to_8
genintamm, 1_to_8
ab_sfammuitems02, 1_to_8
ammu_2flrprops, 1_to_8
lod_countryn, 1linefreewyLOD
hosbibalsfw, 2hospital1sfw
hosbibalsfw, 2hospital2sfw
hosbibalsfw, 2hospital3sfw
lod8sfw, 2hospital3sfwlod
hosbibalsfw, 2hospital4sfw
hosbibalsfw, 2hospital5sfw
hosbibalsfw, 2hospital6sfw
hosbibalsfw, 2hospital7sfw
ce_lod_04, 2laneverge
lahillsa_lod, 2laneverge
lahillsa_lod, 2lanewhiteline
melrose15_lawn, 2winsmel_law
hillhousex_la10_12, 3winstone_law
ebeachcineblok, 3winstone_law
lae2bigblock, 3winstone_law
...

As you can see file 2 has some childs that are repeated, these should be removed. That's why I set the Child Names column to unique. As long as the Child Names are unique the database will be fine, the Parent Names and Models can be repeated.

My problem is that I don't have any SQL experience and I don't know how I can iterate through both files and insert the data as I need. I am thinking a batch file and the 'sqlcmd' command line command would do, but I don't know where to start. I hardly have any batch file experience. So, how do I insert the data?

Aucun commentaire:

Enregistrer un commentaire