Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Trying to replace local file links with actual file contents

Trying to replace local file links with actual file contents

Scheduled Pinned Locked Moved Database
databasemysqlsql-serversysadminhelp
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    J Snape
    wrote on last edited by
    #1

    I've been trying to do this for while and haven't made any progress. I have a tab-delimited file with records for a database file. One of the fields has a local file link for a text file. Each record points to a different text file and there are 151,806 rows, so replacing the file names ("C:\files\LAW_SECTION_TBL_1.lob", "C:\files\LAW_SECTION_TBL_2.lob", ..., "C:\files\LAW_SECTION_TBL_151806.lob") one-by-one with the file text will take a decade or so. The .lob files are utf-8 plain text files. I'd like to load the text files into the individual records as I insert all the data, but I'm not sure how to do it. The file I have to load it into MySQL has the following lines (shortened to essentials only):

    ...
    ,HISTORY
    ,@var1 // Where the "C:\files\LAW_SECTION_TBL_1.lob" is stored
    ,ACTIVE_FLG
    ,TRANS_UID
    ,TRANS_UPDATE
    )
    SET CONTENT_XML=LOAD_FILE(concat('c:\\files\\',@var1))

    I just don't know how to do it for MS SQL Server. Any help or links to webpages that will help me write this INSERT statement are extremely appreciated!

    J J 2 Replies Last reply
    0
    • J J Snape

      I've been trying to do this for while and haven't made any progress. I have a tab-delimited file with records for a database file. One of the fields has a local file link for a text file. Each record points to a different text file and there are 151,806 rows, so replacing the file names ("C:\files\LAW_SECTION_TBL_1.lob", "C:\files\LAW_SECTION_TBL_2.lob", ..., "C:\files\LAW_SECTION_TBL_151806.lob") one-by-one with the file text will take a decade or so. The .lob files are utf-8 plain text files. I'd like to load the text files into the individual records as I insert all the data, but I'm not sure how to do it. The file I have to load it into MySQL has the following lines (shortened to essentials only):

      ...
      ,HISTORY
      ,@var1 // Where the "C:\files\LAW_SECTION_TBL_1.lob" is stored
      ,ACTIVE_FLG
      ,TRANS_UID
      ,TRANS_UPDATE
      )
      SET CONTENT_XML=LOAD_FILE(concat('c:\\files\\',@var1))

      I just don't know how to do it for MS SQL Server. Any help or links to webpages that will help me write this INSERT statement are extremely appreciated!

      J Offline
      J Offline
      J Snape
      wrote on last edited by
      #2

      I figured it out in Excel using the following code on a macro:

      Sub Button1_Click()
      Dim TextFile As Integer
      Dim FilePath As String
      Dim FileContent As String

      Dim i As Long
      For i = 2 To 151807
          
          FilePath = "C:\\pubinfo\\" & Cells(i, 8).Value
          
              TextFile = FreeFile
              Open FilePath For Input As TextFile
              FileContent = Input(LOF(TextFile), TextFile)
              Close TextFile
              
          FileContent = Right(FileContent, Len(FileContent) - 74)
          FileContent = Left(FileContent, Len(FileContent) - 15)
          
          Cells(i, 9).Value = FileContent
      Next i
      

      End Sub

      It took about two hours to pull in all the text, by the way!

      1 Reply Last reply
      0
      • J J Snape

        I've been trying to do this for while and haven't made any progress. I have a tab-delimited file with records for a database file. One of the fields has a local file link for a text file. Each record points to a different text file and there are 151,806 rows, so replacing the file names ("C:\files\LAW_SECTION_TBL_1.lob", "C:\files\LAW_SECTION_TBL_2.lob", ..., "C:\files\LAW_SECTION_TBL_151806.lob") one-by-one with the file text will take a decade or so. The .lob files are utf-8 plain text files. I'd like to load the text files into the individual records as I insert all the data, but I'm not sure how to do it. The file I have to load it into MySQL has the following lines (shortened to essentials only):

        ...
        ,HISTORY
        ,@var1 // Where the "C:\files\LAW_SECTION_TBL_1.lob" is stored
        ,ACTIVE_FLG
        ,TRANS_UID
        ,TRANS_UPDATE
        )
        SET CONTENT_XML=LOAD_FILE(concat('c:\\files\\',@var1))

        I just don't know how to do it for MS SQL Server. Any help or links to webpages that will help me write this INSERT statement are extremely appreciated!

        J Offline
        J Offline
        jschell
        wrote on last edited by
        #3

        Just noting.... "lob", from the file name suggests binary data. In general, programming languages differentiate between binary and text data. Your code used a "String" type. That works under one or both of the following conditions. 1. The files wear in fact text 2. Excel did not attempt to translate them. You can validate the above by exporting at least one file and verifying that it matches the input both in length and content.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups