Solved

drop table

Posted on 2010-11-08
7
386 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Get HTML5 Certified

Want to be a web developer? You'll need to know HTML. Prepare for HTML5 certification by enrolling in July's Course of the Month! It's free for Premium Members, Team Accounts, and Qualified Experts.

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…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

630 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