Solved

drop table

Posted on 2010-11-08
7
378 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
Comment Utility
Forgot to mention that - using microsoft access 2003
0
 
LVL 17

Assisted Solution

by:shinuq
shinuq earned 150 total points
Comment Utility

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
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Author Comment

by:philsivyer
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

In Ruby, Call or invoke a API DLL library is easily via Win32API class, win32-api gem or other gems. For general DLL API call, there are quite a few references, some good tips list below: http://www.rubytips.org/2008/05/13/accessing-windows-api-fro…
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…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

744 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now