Solved

drop table

Posted on 2010-11-08
7
379 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:shinuq
shinuq 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to Open a .RHTML File on Windows 1 342
searching text files for email addresses 3 233
ruby on rails date formatting 1 155
vagrant box not showing up on virtual box 9 711
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…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

929 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

8 Experts available now in Live!

Get 1:1 Help Now