[vwnc] Inserting file in DB from smalltalk

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

[vwnc] Inserting file in DB from smalltalk

Syed Mahdi


Hi

I am new in smalltalk, and am loving its complier and debugging facilities but because of its differences with other " typical"
languages im running into problems for which I would easily find solutions over the web. May be anyone of you would be able to help
me. May be I am just missing out some steps.

So here is the problem:
I am trying to insert a file in my SQL server 2005 DB and I get an error when I get to the part where the filedata is being read
into the SQL insert statement
[CODE]
       
1>tempINT:='123'.
2>upload := (request anyFormValueAt: 'fileBeingUploaded') value.
3>fileName :=  (request anyFormValueAt: 'fileName') value.
4>tempName:=fileName.

5>tempData:=   upload value asByteArray. "getting fileData"

6>connection := Database.MS_SQLServerConnection new.
7> connection
                username: 'usrnm';
                password: 'paswd'.
8> connection environment:
                        'Driver={SQL Native Client};Server=SYED;Database=MYDB;Uid=usrnm;Pwd=paswd;'.
9> connection connect.
10> session := connection getSession.
11> session
                prepare:
                                'INSERT INTO TBFile(SYSID,FILENAME,FILEDATA) VALUES(', tempINT,',',tempName,',',tempData,')'.
12> session execute.
13> ansStrm := session answer.
14> ansStrm := session answer.
[/CODE]
 On line 11> I get error when my debugger comes to tempData and just says " Strings should contain characters" : is it because its
expecting a string because prepare takes a String.
My aim is to store a file in the DB for our application and this is supposed to be a very simple task in other languages but I am
stuck ( conceptually and programatically) on how to solve this issue.

I would really appreciate if any one can help on this. Thanks in advance.
Thanks.
Regards,
Syed Mahdi
Software Engineer



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Inserting file in DB from smalltalk

Mark Roberts
Looking quickly, it seems that either tempName or tempData are not
Strings, and so when you try to concatenate them you get an exception.

Also, I think it might be faster and more efficient to use some kind
of input binding. Using the VisualWorks EXDI, you can bind your
variables with #bindInput:. Have a look at the "Database Application
Developer's Guide" in the /doc subdirectory. Search for "bindInput"
and you'll find some examples and discussion.

HTH,

M. Roberts
Cincom Systems, Inc.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Inserting file in DB from smalltalk

Syed Mahdi


Hi
 I am so thankful for your fast response. I didn't really expect such a fast response.
Actually I am not concatenating it. So yes they are not strings. tempData is supposed to be the file that I uploaded in byteArrays.
And tempName is a string refering to the fileName.

But yes I will try to Bind it and see if that works.
Really apprecaite it.
Thanks.
Regards,
Syed Mahdi
Software Engineer

Omnitec International,P.O. Box 500229, Dubai Internet City, U.A.E.
 
Tel.: +971-4-3616798
Fax: +971-4-3908521
E-Mail: [hidden email]

-----Original Message-----
From: Mark D. Roberts [mailto:[hidden email]]
Sent: Monday, September 01, 2008 12:39 PM
To: Syed Mahdi
Cc: [hidden email]
Subject: Re: [vwnc] Inserting file in DB from smalltalk

Looking quickly, it seems that either tempName or tempData are not
Strings, and so when you try to concatenate them you get an exception.

Also, I think it might be faster and more efficient to use some kind
of input binding. Using the VisualWorks EXDI, you can bind your
variables with #bindInput:. Have a look at the "Database Application
Developer's Guide" in the /doc subdirectory. Search for "bindInput"
and you'll find some examples and discussion.

HTH,

M. Roberts
Cincom Systems, Inc.


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Inserting file in DB from smalltalk

Björn Eiderbäck-3
In reply to this post by Syed Mahdi
Maybe you have to convert non string values to strings before concatenation.
As in:

tempINT:='123'.
tempData := #(1 2 3) asByteArray.
tempName := 'AFileName'.

'INSERT INTO TBFile(SYSID,FILENAME,FILEDATA) VALUES(', tempINT,',',tempName,',', tempData printString,')'

Where tempData is sent the message printString.

/Björn

-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Syed Mahdi
Sent: den 1 september 2008 10:12
To: [hidden email]
Subject: [vwnc] Inserting file in DB from smalltalk



Hi

I am new in smalltalk, and am loving its complier and debugging facilities but because of its differences with other " typical"
languages im running into problems for which I would easily find solutions over the web. May be anyone of you would be able to help
me. May be I am just missing out some steps.

So here is the problem:
I am trying to insert a file in my SQL server 2005 DB and I get an error when I get to the part where the filedata is being read
into the SQL insert statement
[CODE]
       
1>tempINT:='123'.
2>upload := (request anyFormValueAt: 'fileBeingUploaded') value.
3>fileName :=  (request anyFormValueAt: 'fileName') value.
4>tempName:=fileName.

5>tempData:=   upload value asByteArray. "getting fileData"

6>connection := Database.MS_SQLServerConnection new.
7> connection
                username: 'usrnm';
                password: 'paswd'.
8> connection environment:
                        'Driver={SQL Native Client};Server=SYED;Database=MYDB;Uid=usrnm;Pwd=paswd;'.
9> connection connect.
10> session := connection getSession.
11> session
                prepare:
                                'INSERT INTO TBFile(SYSID,FILENAME,FILEDATA) VALUES(', tempINT,',',tempName,',',tempData,')'.
12> session execute.
13> ansStrm := session answer.
14> ansStrm := session answer.
[/CODE]
 On line 11> I get error when my debugger comes to tempData and just says " Strings should contain characters" : is it because its
expecting a string because prepare takes a String.
My aim is to store a file in the DB for our application and this is supposed to be a very simple task in other languages but I am
stuck ( conceptually and programatically) on how to solve this issue.

I would really appreciate if any one can help on this. Thanks in advance.
Thanks.
Regards,
Syed Mahdi
Software Engineer



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Inserting file in DB from smalltalk

Wouter Gazendam-2-2
In reply to this post by Syed Mahdi
Perhaps using #bindInput: would help here:

session
        prepare: 'INSERT INTO TBFile(SYSID,FILENAME,FILEDATA) VALUES(:1, :2, :3)';
        bindInput: (Array with: tempINT with: tempName with: tempData)


HTH,

Wouter

On Mon, Sep 1, 2008 at 10:44 AM, Syed Mahdi <[hidden email]> wrote:

>
>
> Hi
>  I am so thankful for your fast response. I didn't really expect such a fast response.
> Actually I am not concatenating it. So yes they are not strings. tempData is supposed to be the file that I uploaded in byteArrays.
> And tempName is a string refering to the fileName.
>
> But yes I will try to Bind it and see if that works.
> Really apprecaite it.
> Thanks.
> Regards,
> Syed Mahdi
> Software Engineer
>
> Omnitec International,P.O. Box 500229, Dubai Internet City, U.A.E.
>
> Tel.: +971-4-3616798
> Fax: +971-4-3908521
> E-Mail: [hidden email]
>
> -----Original Message-----
> From: Mark D. Roberts [mailto:[hidden email]]
> Sent: Monday, September 01, 2008 12:39 PM
> To: Syed Mahdi
> Cc: [hidden email]
> Subject: Re: [vwnc] Inserting file in DB from smalltalk
>
> Looking quickly, it seems that either tempName or tempData are not
> Strings, and so when you try to concatenate them you get an exception.
>
> Also, I think it might be faster and more efficient to use some kind
> of input binding. Using the VisualWorks EXDI, you can bind your
> variables with #bindInput:. Have a look at the "Database Application
> Developer's Guide" in the /doc subdirectory. Search for "bindInput"
> and you'll find some examples and discussion.
>
> HTH,
>
> M. Roberts
> Cincom Systems, Inc.
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>



--
Met vriendelijke groet,

Wouter Gazendam
AG5 B.V.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Inserting file in DB from smalltalk

Wouter Gazendam
Perhaps using #bindInput: would help here:

session
       prepare: 'INSERT INTO TBFile(SYSID,FILENAME,FILEDATA)
VALUES(:1, :2, :3)';
       bindInput: (Array with: tempINT with: tempName with: tempData)


HTH,

Wouter

On Mon, Sep 1, 2008 at 10:44 AM, Syed Mahdi <[hidden email]> wrote:

>
>
> Hi
>  I am so thankful for your fast response. I didn't really expect such a fast response.
> Actually I am not concatenating it. So yes they are not strings. tempData is supposed to be the file that I uploaded in byteArrays.
> And tempName is a string refering to the fileName.
>
> But yes I will try to Bind it and see if that works.
> Really apprecaite it.
> Thanks.
> Regards,
> Syed Mahdi
> Software Engineer
>
> Omnitec International,P.O. Box 500229, Dubai Internet City, U.A.E.
>
> Tel.: +971-4-3616798
> Fax: +971-4-3908521
> E-Mail: [hidden email]
>
> -----Original Message-----
> From: Mark D. Roberts [mailto:[hidden email]]
> Sent: Monday, September 01, 2008 12:39 PM
> To: Syed Mahdi
> Cc: [hidden email]
> Subject: Re: [vwnc] Inserting file in DB from smalltalk
>
> Looking quickly, it seems that either tempName or tempData are not
> Strings, and so when you try to concatenate them you get an exception.
>
> Also, I think it might be faster and more efficient to use some kind
> of input binding. Using the VisualWorks EXDI, you can bind your
> variables with #bindInput:. Have a look at the "Database Application
> Developer's Guide" in the /doc subdirectory. Search for "bindInput"
> and you'll find some examples and discussion.
>
> HTH,
>
> M. Roberts
> Cincom Systems, Inc.
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>



--
Met vriendelijke groet,

Wouter Gazendam
AG5 B.V.
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [vwnc] Inserting file in DB from smalltalk

Syed Mahdi
In reply to this post by Wouter Gazendam-2-2


Hi
I am so grateul. I am able to write the file into the DB. (it stores as <binary data>).
#bindInput solved the problem perfectly. Thanks to all of you. With every digest I receive I learn more and more of smalltalk. Im
already loving it.

Now I will bang my head in retreiving the file back and show/play it and If I cant on my own then I will come to you guys again.
Hopefully I will do it on my own. Thanks Again.  
 
Thanks.
Regards,
Syed Mahdi
Software Engineer

-----Original Message-----
From: Wouter Gazendam [mailto:[hidden email]]
Sent: Monday, September 01, 2008 12:55 PM
To: Syed Mahdi
Cc: Mark D. Roberts; [hidden email]
Subject: Re: [vwnc] Inserting file in DB from smalltalk

Perhaps using #bindInput: would help here:

session
        prepare: 'INSERT INTO TBFile(SYSID,FILENAME,FILEDATA) VALUES(:1, :2, :3)';
        bindInput: (Array with: tempINT with: tempName with: tempData)


HTH,

Wouter

On Mon, Sep 1, 2008 at 10:44 AM, Syed Mahdi <[hidden email]> wrote:
>
>
> Hi
>  I am so thankful for your fast response. I didn't really expect such a fast response.
> Actually I am not concatenating it. So yes they are not strings. tempData is supposed to be the file that I uploaded in
byteArrays.

> And tempName is a string refering to the fileName.
>
> But yes I will try to Bind it and see if that works.
> Really apprecaite it.
> Thanks.
> Regards,
> Syed Mahdi
> Software Engineer
>
> Omnitec International,P.O. Box 500229, Dubai Internet City, U.A.E.
>
> Tel.: +971-4-3616798
> Fax: +971-4-3908521
> E-Mail: [hidden email]
>
> -----Original Message-----
> From: Mark D. Roberts [mailto:[hidden email]]
> Sent: Monday, September 01, 2008 12:39 PM
> To: Syed Mahdi
> Cc: [hidden email]
> Subject: Re: [vwnc] Inserting file in DB from smalltalk
>
> Looking quickly, it seems that either tempName or tempData are not
> Strings, and so when you try to concatenate them you get an exception.
>
> Also, I think it might be faster and more efficient to use some kind
> of input binding. Using the VisualWorks EXDI, you can bind your
> variables with #bindInput:. Have a look at the "Database Application
> Developer's Guide" in the /doc subdirectory. Search for "bindInput"
> and you'll find some examples and discussion.
>
> HTH,
>
> M. Roberts
> Cincom Systems, Inc.
>
>
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>



--
Met vriendelijke groet,

Wouter Gazendam
AG5 B.V.

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc