[HOW TO] send picture to VSERVER
Ruslan Zasukhin
ruslan_zasukhin at valentina-db.com
Sun May 13 02:16:00 CDT 2012
On 5/12/12 5:15 PM, "Fabian Kneubuehl" <support at ysd.ch> wrote:
Hi All,
About SQL way ...
HOW TO send picture/blob using SQL way and working with VSERVER.
======================================
1) INSERT command.
Let I want insert new record into table, some normal fields and some
Picture...
!!! EVERYBODY should prefer to use BINDING, many articles on inet why ...
ATTENTION: work with array will differ for different ADKs
I show here only major basic idea...
BindValues(1) = "FirstName"
BindValues(2) = "LastName"
BindValues(3) = "ElseInfo"
BindValues(4) = somePicture
Db.SqlExecute(
"INSERT INTO T(f1,f2,f3,f4) VALUES(:1,:2,:3,:4)" , bindValues )
WHAT IS GOOD here.
We prepare on client side array.
We then send this all at once to REMOTE vserver as single command.
Binding ensure small SQL string to parse.
Binding also prevent SQL injections attacks
======================================
2) UPDATE command
All the same in fact as with insert, just UPDATE command,
And usually exists WHERE clause where you specify RecID of record you want
update
BindValues(1) = "FirstName"
BindValues(2) = "LastName"
BindValues(3) = "ElseInfo"
BindValues(4) = somePicture
BindValues(5) = 549 // row you want to update
Db.SqlExecute(
"UPDATE T SET f1=:1, f2 = :2, f3=:3, f4=:4 WHERE RecID = :5" ,
bindValues )
Again, all is simple and clear....
Single command to vserver.
While vserver will update this record, any other user can touch it.
======================================
3) using SQL way, but Vcursor class
Since we want add/update records, we need ask for ServerSide and ReadWrite
cursor.
---------------
3a) to ADD records, usually we should ask for EMPTY cursor
Vcursor curs = db.SqlSelect( "SELECT f1,f2,f3,f4 FROM T WHERE false",
kServerSide, kReadWrite )
curs.VarCharField( "f1" ).value = "FirstName"
curs.VarCharField( "f2" ).value = "LastName"
curs.VarCharField( "f3" ).value = "else"
curs.VarCharField( "f4" ).value = somePicture
Curs.AddRecord()
Curs = nil
---------------
3b) to UPDATE records
Vcursor curs = db.SqlSelect( "SELECT f1,f2,f3,f4 FROM T WHERE RecID=549",
kServerSide, kReadWrite )
curs.VarCharField( "f1" ).value = "FirstName"
curs.VarCharField( "f2" ).value = "LastName"
curs.VarCharField( "f3" ).value = "else"
curs.VarCharField( "f4" ).value = somePicture
Curs.UpdateRecord()
Curs = nil
======================================
When you can prefer to use Vcursor to direct SQLcommands?
I think, cursors can be better if you also need show its records
into some grid ...
If no need to display record, but just to fill into db,
Then direct commands are more logical.
--
Best regards,
Ruslan Zasukhin
VP Engineering and New Technology
Paradigma Software, Inc
Valentina - Joining Worlds of Information
http://www.paradigmasoft.com
[I feel the need: the need for speed]
More information about the Valentina
mailing list