News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Sql Server & Masm32

Started by mabdelouahab, April 22, 2016, 01:31:31 AM

Previous topic - Next topic

mabdelouahab

Add SQL Parameters
Methods
    -------------------------------------------------------------------------------------------------------------------------------------
For SqlDbType: Binary, Image, Timestamp, VarBinary:
    AddArrayOfByteParameter:
         Arg: 
            pSqlCommand: System.Data.SqlClient.SqlCommand Object (from CreateSqlCommand method)
            _parameterName : ptr to parameter Name
            _nByte: The number of bytes to be passed
            _pByte: Ptr to the first byte

Quote   
   ;byte[]: SqlDbType.Binary, SqlDbType.Image, SqlDbType.Timestamp, SqlDbType.VarBinary
   AddArrayOfByteParameter PROC pSqlCommand,_parameterName,_nByte,_pByte
      LOCAL VarValue:VARIANT
      .data
         __byteArray   SAFEARRAY   <>
      .code
      lea ecx,__byteArray
      mov [ecx].SAFEARRAY.cDims              ,1
      mov [ecx].SAFEARRAY.fFeatures          ,0
                mov [ecx].SAFEARRAY.cbElements         ,1
      mov [ecx].SAFEARRAY.cLocks             ,0
      mov eax,_pByte
      mov [ecx].SAFEARRAY.pvData             ,eax
      mov eax,_nByte
      mov [ecx].SAFEARRAY.rgsabound.cElements   ,EAX
      mov [ecx].SAFEARRAY.rgsabound.lLbound   ,0 
   
      mov    VarValue.vt,VT_ARRAY OR VT_UI1
      mov    VarValue.parray,ecx
      
      invoke AddParameter,pSqlCommand,_parameterName,addr VarValue
      ret

   AddArrayOfByteParameter endp

Example :

Quote

               invoke AddColumnToSQLTable ,chr$("MyDataBase"),
                                    chr$("MyTable"),
                                    chr$("column01"),
                                    chr$(" Binary(3) ")            
               invoke AddColumnToSQLTable ,chr$("MyDataBase"),
                                    chr$("MyTable"),
                                    chr$("column02"),
                                    chr$(" Image ")            
               invoke AddColumnToSQLTable ,chr$("MyDataBase"),
                                    chr$("MyTable"),
                                    chr$("column03"),
                                    chr$(" Timestamp ")            
               invoke AddColumnToSQLTable ,chr$("MyDataBase"),
                                    chr$("MyTable"),
                                    chr$("column04"),
                                    chr$(" VarBinary(10) ")            

....
                  .data
                     arrByte   db   1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17
                  .code
                     invoke SetCommandText,_SqlCommand,chr$(" INSERT INTO MyTable (column01,column02,column04)VALUES (@p1,@A2,@param); ")
                     invoke AddArrayOfByteParameter,_SqlCommand,chr$("@p1"),3,addr arrByte
                     invoke AddArrayOfByteParameter,_SqlCommand,chr$("@param"),10,addr arrByte
                     invoke AddArrayOfByteParameter,_SqlCommand,chr$("@A2"),15,addr arrByte
                     invoke ExecuteNonQuery,_SqlCommand
         

Quote
timestamp (Transact-SQL)

Is a data type that exposes automatically generated, unique binary numbers within a database. timestamp is generally used as a mechanism for version-stamping table rows. The storage size is 8 bytes. The timestamp data type is just an incrementing number and does not preserve a date or a time. To record a date or time, use a datetime data type.
Remarks
Each database has a counter that is incremented for each insert or update operation that is performed on a table that contains a timestamp column within the database. This counter is the database timestamp. This tracks a relative time within a database, not an actual time that can be associated with a clock. A table can have only one timestamp column. Every time that a row with a timestamp column is modified or inserted, the incremented database timestamp value is inserted in the timestamp column. This property makes a timestamp column a poor candidate for keys, especially primary keys. Any update made to the row changes the timestamp value and, therefore, changes the key value. If the column is in a primary key, the old key value is no longer valid, and foreign keys referencing the old value are no longer valid. If the table is referenced in a dynamic cursor, all updates change the position of the rows in the cursor. If the column is in an index key, all updates to the data row also generate updates of the index
From:https://msdn.microsoft.com/en-us/library/ms182776(v=sql.90).aspx