Tinytds - Save binary as file

Hello,

I'm learning Ruby and I'm trying to save to disk some content that is in
sql server in a column of type 'Image'.

Problem is that the column with the content always have the same
size(4096) whem I'm iterating through the results.

My code so far:

client = TinyTds::Client.new(:username => 'someuser', :password =>
'somepass', :dataserver => 'someserver', :database => 'somedb')
result = client.execute("SELECT top 5 Content,DirName,LeafName FROM
sometable where ListID='819B' AND Content is not null")

result.each do |row|
  directory_name = File.join("d:" , row["DirName"])
  FileUtils.mkdir_p(directory_name) unless File.exists?(directory_name)

  filename = File.join(directory_name , row["LeafName"])

  p row["Content"].length # Always returns 4096...

  File.open(filename, "w") do |myfile|
      myfile.write(row["Content"])
  end
end

···

--
Posted via http://www.ruby-forum.com/.

Quoting Miguel Mendes (lists@ruby-forum.com):

  File.open(filename, "w") do |myfile|

If you want to write binary (i.e. unadulterated) content, you must add
a 'b', as follows:

   File.open(filename, "wb") do |myfile|

Carlo

···

Subject: Tinytds - Save binary as file
  Date: Sat 22 Dec 12 02:42:55AM +0900

--
  * Se la Strada e la sua Virtu' non fossero state messe da parte,
* K * Carlo E. Prelz - fluido@fluido.as che bisogno ci sarebbe
  * di parlare tanto di amore e di rettitudine? (Chuang-Tzu)

Can you show the table schema?

···

On Fri, Dec 21, 2012 at 11:42 AM, Miguel Mendes <lists@ruby-forum.com> wrote:

Hello,

I'm learning Ruby and I'm trying to save to disk some content that is in
sql server in a column of type 'Image'.

Problem is that the column with the content always have the same
size(4096) whem I'm iterating through the results.

My code so far:

client = TinyTds::Client.new(:username => 'someuser', :password =>
'somepass', :dataserver => 'someserver', :database => 'somedb')
result = client.execute("SELECT top 5 Content,DirName,LeafName FROM
sometable where ListID='819B' AND Content is not null")

result.each do |row|
  directory_name = File.join("d:" , row["DirName"])
  FileUtils.mkdir_p(directory_name) unless File.exists?(directory_name)

  filename = File.join(directory_name , row["LeafName"])

  p row["Content"].length # Always returns 4096...

  File.open(filename, "w") do |myfile|
      myfile.write(row["Content"])
  end
end

--
Posted via http://www.ruby-forum.com/\.

"wb" didn't work.

Here is the table schema

CREATE TABLE [dbo].[Docs](
  [Id] [uniqueidentifier] NOT NULL,
  [ListId] [uniqueidentifier] NOT NULL,
  [DirName] [nvarchar](256) NOT NULL,
  [LeafName] [nvarchar](128) NOT NULL,
  [Content] [image] NULL)

···

--
Posted via http://www.ruby-forum.com/.

hi

Attachments:
http://www.ruby-forum.com/attachment/8100/DifferenDiagnosisPhysical-godman.pdf

···

--
Posted via http://www.ruby-forum.com/.

See here

The default is 4Kb when no size parameter is specified

Also see
https://groups.google.com/forum/#!msg/rails-sqlserver-adapter/uRq9355DP94/wpH1d3TVHFEJ
seems there is a config file that can impact size of data returned

···

On Wed, Dec 26, 2012 at 5:00 AM, Miguel Mendes <lists@ruby-forum.com> wrote:

"wb" didn't work.

Here is the table schema

CREATE TABLE [dbo].[Docs](
  [Id] [uniqueidentifier] NOT NULL,
  [ListId] [uniqueidentifier] NOT NULL,
  [DirName] [nvarchar](256) NOT NULL,
  [LeafName] [nvarchar](128) NOT NULL,
  [Content] [image] NULL)

--
Posted via http://www.ruby-forum.com/\.

unsubscribe

···

On Fri, Feb 1, 2013 at 7:54 PM, Chris Hulan <chris.hulan@gmail.com> wrote:

See here
http://msdn.microsoft.com/en-us/library/ms187365.aspx
The default is 4Kb when no size parameter is specified

Also see

Redirecting to Google Groups
seems there is a config file that can impact size of data returned

On Wed, Dec 26, 2012 at 5:00 AM, Miguel Mendes <lists@ruby-forum.com>wrote:

"wb" didn't work.

Here is the table schema

CREATE TABLE [dbo].[Docs](
  [Id] [uniqueidentifier] NOT NULL,
  [ListId] [uniqueidentifier] NOT NULL,
  [DirName] [nvarchar](256) NOT NULL,
  [LeafName] [nvarchar](128) NOT NULL,
  [Content] [image] NULL)

--
Posted via http://www.ruby-forum.com/\.