Solved

drop table

Posted on 2010-11-08
7
384 Views
Last Modified: 2012-05-10
Below is my script which works - but need to know how to drop the table footy and recreate it again before uploading data.


INPUT_DATAFILE = "u:/footy/footy.txt"

 require 'win32ole'
 connection = WIN32OLE.new('ADODB.Connection')
 connection.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=u:\footy\footy.mdb')


File.open(INPUT_DATAFILE) do |f|
  while line = f.gets
    values = line.split("\t")   #  data is tab delimited
    sql = ("INSERT INTO footy VALUES ('#{values[0]}', '#{values[1]}','#{values[2]}');")
    puts sql
     connection.Execute(sql)
  end
end

Regards
0
Comment
Question by:philsivyer
7 Comments
 

Author Comment

by:philsivyer
ID: 34083214
Forgot to mention that - using microsoft access 2003
0
 
LVL 17

Assisted Solution

by:Shinesh Premrajan
Shinesh Premrajan earned 150 total points
ID: 34083253

INPUT_DATAFILE = "u:/footy/footy.txt"

 require 'win32ole'
 connection = WIN32OLE.new('ADODB.Connection')
 connection.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=u:\footy\footy.mdb')

sql = ("drop table footy;")
puts sql
connection.Execute(sql)

sql = ("create table footy(name varcahr(100));") // need to have the column names here
puts sql
connection.Execute(sql)

File.open(INPUT_DATAFILE) do |f|
  while line = f.gets
    values = line.split("\t")   #  data is tab delimited
    sql = ("INSERT INTO footy VALUES ('#{values[0]}', '#{values[1]}','#{values[2]}');")
    puts sql
     connection.Execute(sql)
  end
end


Hope this helps
0
 
LVL 58

Expert Comment

by:cyberkiwi
ID: 34083255
Don't drop it if you are only going to recreate.
Empty it instead:

Before this statement
    sql = ("INSERT INTO footy VALUES ('#{values[0]}', '#{values[1]}','#{values[2]}');")
Run this statement
    sql = ("DELETE * FROM footy")
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:philsivyer
ID: 34083294
When I use
sql = ("DELETE * FROM footy")
It does not complete the cycle and seems to hang - I am running this from ScITE.
0
 
LVL 58

Accepted Solution

by:
cyberkiwi earned 300 total points
ID: 34083299
That wasn't the full code, just pseudo to show the Access query..
INPUT_DATAFILE = "u:/footy/footy.txt"

 require 'win32ole'
 connection = WIN32OLE.new('ADODB.Connection')
 connection.Open('Provider=Microsoft.Jet.OLEDB.4.0;Data Source=u:\footy\footy.mdb')

    sql = ("DELETE * FROM footy")
    puts sql
     connection.Execute(sql)

File.open(INPUT_DATAFILE) do |f|
  while line = f.gets
    values = line.split("\t")   #  data is tab delimited
    sql = ("INSERT INTO footy VALUES ('#{values[0]}', '#{values[1]}','#{values[2]}');")
    puts sql
     connection.Execute(sql)
  end
end

Open in new window

0
 

Author Comment

by:philsivyer
ID: 34083319
Thats great - any good sites/books for ruby and windows (excel access etc)
0
 
LVL 12

Assisted Solution

by:JESii
JESii earned 50 total points
ID: 34083434
Check out: http://rubyonwindows.blogspot.com/2007/03/automating-excel-with-ruby.html which gives some information on automating excel. There's also a reference to another library in the comments to the post.

I'm starting on a ruby project which uses Excel files as intermediaries -- they're already using a couple of gems and I'll try to get that info and post it here as soon as I learn more.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently rediscovered rails when I needed a holiday project and decided to build a management dashboard for the company where I work.  With it being a project done in my free time, I could focus my time on learning the basics rather than trying to…
Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question