Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sp_OAMethod 'OpenTextFile' clarification

I can seem to find an answer to this even on Microsoft sites I am using this:

EXECUTE @RetCode = sp_OAMethod @FileSystem, 
 'OpenTextFile',
 @FileHandle OUTPUT,
 @FilePath,
 8,
 1

I would like to know what the finale int parameter (1) does and what other options there are for this. I experimented and used 2 but did not see any difference.

I know that the second last int parameter (8) specifies an append vs using 2 a write but do not know of other values for this parameter either.

like image 566
HelloWorld Avatar asked Dec 19 '22 21:12

HelloWorld


1 Answers

The sp_OAMethod is executing method of the given object, in this case is a FileSystemObject OpenTextFile has 4 parameters in this order:

  1. FilePath -Required. The name of the file to open
  2. Mode - Optional. How to open the file
    • 1 = Reading - Open a file for reading. You cannot write to this file.
    • 2 = Writing - Open a file for writing.
    • 8 = Appending - Open a file and write to the end of the file.
  3. Create - Optional. Sets whether a new file can be created if the filename does not exist. True indicates that a new file can be created, and False indicates that a new file will not be created. False is default.
  4. Format - Optional. The format of the file
    • 0 = TristateFalse - Open the file as ASCII. This is default.
    • 1 = TristateTrue - Open the file as Unicode.
    • 2 = TristateUseDefault - Open the file using the system default.

In your case (8) is the Mode, and (1) is the Create. You can read more about it here.

like image 100
Ben Ohana Avatar answered Jan 06 '23 08:01

Ben Ohana