Insert and Retrieve binary objects with MS-SQL 2000

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Insert and Retrieve binary objects with MS-SQL 2000

    Alrighty then,

    I have searched the web abd CF forums for the past 2 months trying to find a
    code snippet for inserting a binary object into a MS-SQL 2000 db.

    I am trying to insert an MS-Office document (whether it be
    word/excel/powerpoint) into a DB.
    I DO NOT want to store the file in a directory structure of sorts and just
    POINT to it from the DB.
    (which seems to be the suggestion when anyone else has asked a similar
    question.)

    My process steps will be along the lines of...
    get filename from user.
    store filename in appropriate variable
    create UID
    store UID in appropriate variable.
    insert uid + filename + binary object into DB.

    if anyone has some time I would be much appreciative for the assistance.
    I am certain that with a working INSERT snippet I will be able create
    retrieval code myself.

    HeloWorld Guest

  2. Similar Questions and Discussions

    1. Inserting binary field into SQL 2000 database
      Hi, I have been trying to upload a .pdf file to a SQL Server 2000 database. I used the dreamweaver MX auto generated code. However, I have the...
    2. Retrieve Client Certificate using COM Objects
      Anybody knows how to retrieve Client Certificate using COM objects instead of: var=Request.ClientCertificate("certificate"); Thanks
    3. How to store objects in array and the retrieve them
      Hi, I'm trying to store objects in an array and then later I want to retrieve the object again. I tried it the following way, but it doesn't...
    4. Mysql and binary data insert
      Hello, I have a question, how to insert binary data into the table by MySql DBI module ? Thanks Michal Weinfurtner
    5. How can I retrieve my Site Definitions in my new MSWindows 2000 profile
      On Thu, 10 Jul 2003 16:41:49 +0200, Liebste <Liebste00@netscape.net> wrote: Site definitions are stored in the registry key:...
  3. #2

    Default Re: Insert and Retrieve binary objects with MS-SQL 2000

    something like this doesn't work for you?

    <cffile action="READBINARY" file="e:\temp\trendyBlueCast.jpg"
    variable="imageFile">

    <cfquery name="testBinary" datasource="lab">
    INSERT testBinary(docType,theFile)
    VALUES('jpeg',<cfqueryparam cfsqltype="CF_SQL_BLOB" value="#imageFile#"
    null="No">)
    </cfquery>

    PaulH Guest

  4. #3

    Default Re: Insert and Retrieve binary objects with MS-SQL 2000

    Hi Paul,

    thanks for the reply...
    TYou suggested I use the following :
    VALUES('jpeg',<cfqueryparam cfsqltype="CF_SQL_BLOB" value="#imageFile#"
    null="No">)
    </cfquery>

    I take I am replacing the VALUES('JPEG' with
    VALUES('doc'... if it is a word document and 'x's' if its an excel document?

    And, while I have your attention... what the heck does cfqueryparam do?
    I haven''t seen/used this tag before.

    HeloWorld Guest

  5. #4

    Default Re: Insert and Retrieve binary objects with MS-SQL 2000

    that was just an example, though if you want to use full-text indexing i think
    you'll need a columns to hold doc type, etc. as for cfqueryparam see
    [url]http://livedocs.macromedia.com/coldfusion/7/htmldocs/wwhelp/wwhimpl/common/html/[/url]
    wwhelp.htm?context=ColdFusion_Documentation&file=0 0000317.htm, to quote the
    docs: "Verifies the data type of a query parameter and, for DBMSs that support
    bind variables, enables ColdFusion to use bind variables in the SQL statement.
    Bind variable usage enhances performance when executing a cfquery statement
    multiple times." further for public facing websites, "Macromedia recommends
    that you use the cfqueryparam tag within every cfquery tag, to help secure your
    databases from unauthorized users."

    its a good practice.



    PaulH Guest

  6. #5

    Default Re: Insert and Retrieve binary objects with MS-SQL 2000

    Just in case any other not-so-nimble minded person ends up searching the MM
    forums for help with inserting MS-Office docs into a DB I have copied in an
    email that finally made sense to me.

    Mind you saying that... know that I actually understand what is going on - the
    other dozen or so threads I have read previously all make sense to me now
    too... - better late than never I suppose!


    Gavin Baumanis wrote:
    > 1) Can I get an example of inserting an office document into a DB.
    i don't think your files being ms office is going to make any
    difference. that example i posted should work ok for your office docs.
    did you try?
    > 2) Will I need to alter the SQL for Document types?
    no you shouldn't. binary is binary. i'm not following your concerns.
    what seems to be the problem?
    > document, therefore I'll need some conditional statements testing/asking
    > for the file type, then using that file type in the VALUES arguments?
    that only matters if you're using full text (i think) and of course when
    you want to use these files then you'd need original file names & types.
    this snippet seems to work ok for me.

    <!--- get a word doc --->
    <cfset theFile="e:\users\paul\cfbooks\6\peachpitpress\cfa dv6 toc 01.doc">
    <cfset fileName=getFileFromPath(theFile)> <!--- file name --->
    <cfset fileExt=listLast(filename,".")> <!--- doc type --->
    <cffile action="READBINARY" file="#theFile#" variable="imageFile">
    <!--- stick in the db --->
    <cfquery name="i" datasource="lab">
    INSERT testBinary(docType,docName,original,theBLOB)
    VALUES('#fileExt#','#fileName#',getDate(),<cfquery param
    cfsqltype="CF_SQL_BLOB" value="#imageFile#" null="No">)
    </cfquery>
    <!--- get it back --->
    <cfquery name="i" datasource="lab">
    SELECT TOP 1 docName,theBLOB
    FROM testBinary
    WHERE docName='#fileName#'
    </cfquery>
    <!--- write it out --->
    <cffile action="WRITE" file="e:\temp\#i.docName#" output="#i.theBlob#"
    addnewline="No" fixnewline="No">
    <!--- did it get there ok? --->
    <cfdirectory action="LIST" filter="#i.docName#" name="docList"
    directory="e:\temp\">
    <cfif docList.recordCount>
    <cfdump var="#docList#">
    <cfelse>
    Something bad happened.
    </cfif>

    and this is the DDL for that test table:
    CREATE TABLE [dbo].[testBinary] (
    [id] [int] IDENTITY (1, 1) NOT NULL ,
    [docType] [varchar] (3) NULL ,
    [docName] [varchar] (50) NULL ,
    [original] [smalldatetime] NULL ,
    [modified] [smalldatetime] NULL ,
    [theBLOB] [image] NULL
    ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
    GO

    A special thanks to PaulH of the MM team....

    HeloWorld Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139