MSSQL OLEDB plug-in: Difference between revisions

From NSIS Wiki
Jump to navigationJump to search
 
(15 intermediate revisions by 4 users not shown)
Line 2: Line 2:


== Download ==
== Download ==
<attach>MSSQL_OLEDB.zip</attach>
<p>
'''Version 2.x: (new plugin API, distinct versions for NON-Unicode and Unicode builds of NSIS)'''<br />
<attach>Mssql_oledb2.zip</attach>
</p>
<p>
'''Version 1.x: (old plugin API, limited support to Unicode scripts)'''<br />
<attach>MSSQL_OLEDB.zip</attach><br />
</p>


== Description ==
== Description ==
Line 9: Line 16:
MSSQL interoperability within an install script
MSSQL interoperability within an install script


'''Version:''' 1.0 12th March 2007. First Release<br>
<p>'''Version:''' 1.0 12th March 2007.<br />
'''Version:''' 1.1 20th March 2007. Fixed bug in DllMain under Windows 2000<br>
* First Release<br /></p>
'''Version:''' 1.2 29th March 2007. Added SQL_ExecuteScript function<br>
<p>'''Version:''' 1.1 20th March 2007.<br />
'''Version:''' 1.3 24th May  2007. Fixed a bug in Data Column Binding causing data truncation in rowsets<br>
* Fixed bug in DllMain under Windows 2000<br /></p>
'''Version:''' 1.4 11th Sept  2007. Added support for Unicode SQL scripts in SQL_ExecuteScript function<br>
<p>'''Version:''' 1.2 29th March 2007.<br />
* Added SQL_ExecuteScript function<br /></p>
<p>'''Version:''' 1.3 24th May  2007.<br />
* Fixed a bug in Data Column Binding causing data truncation in rowsets<br /></p>
<p>'''Version:''' 1.4 11th Sept  2007.<br />
* Added support for Unicode SQL scripts in SQL_ExecuteScript function<br /></p>
<p>'''Version:''' 2.0 11th April 2009.<br />
* Added support for new plugin api.
* Added unicode version (Unicode scripts support is available only in unicode version from now on).
* Script length is only limited by memory<br /></p>
<p>'''Version:''' 2.0.1 1st August 2009.<br />
* Fixed an allocation bug. Global variables were not set to null after deletion in SQL_Logout function.<br /></p>


'''Supported on:''' ''Windows NT, Windows 2000, Windows XP''.
<p>'''Supported on:''' ''Windows NT, Windows 2000, Windows XP,Vista,Win2k3,Win2k8,Seven''.</p>


== Notes ==
== Notes ==


All functions must be called with the /NOUNLOAD switch
* MSSQL_OLEDB.dll is the standard (non Unicode) version of the plugin
Only SQL_Logout must be called as last and without /NOUNLOAD
* UMSSQL_OLEDB.dll is the Unicode version of the plugin
* To execute Unicode scripts the Unicode version of NSIS and the Unicode version of the plugin MUST be used.


== Functions ==
== Functions ==
Line 53: Line 72:


;Excecutes a SQL query contained in a file
;Excecutes a SQL query contained in a file
:<scriptfile> - Path to file containing the script to execute (max 60000 bytes)
:<scriptfile> - Path to file containing the script to execute
   
 
;Returns:     
;Returns:     
:*"0" Success, "1" Failure
:*"0" Success, "1" Failure
:*A message string
:*A message string
               
 
=== SQL_GetRow ===
=== SQL_GetRow ===


Line 68: Line 87:
:*"0" Success, "1" Failure, "2" No more data to read
:*"0" Success, "1" Failure, "2" No more data to read
:*A string containing the row of data (each column is separated by a '|' char). A message in case if error or no more data
:*A string containing the row of data (each column is separated by a '|' char). A message in case if error or no more data
               
 
=== SQL_GetError ===
=== SQL_GetError ===


Line 83: Line 102:
<highlight-nsis>MSSQL_OLEDB::SQL_Logout</highlight-nsis>
<highlight-nsis>MSSQL_OLEDB::SQL_Logout</highlight-nsis>


;Deallocates memory used by dll and logs out of SQL server. Use this function WITHOUT the /NOUNLOAD switch when finished using the plugin
Deallocates memory used by dll and logs out of SQL server.


== Usage Example ==
== Usage Example ==
<highlight-nsis>detailprint "Loggin on to SQL server $SQLSERVER"
<highlight-nsis>detailprint "Loggin on to SQL server $SQLSERVER"
MSSQL_OLEDB::SQL_Logon /NOUNLOAD "$SQLSERVER" "$SQLUSER" "$SQLPASSWORD"
MSSQL_OLEDB::SQL_Logon "$SQLSERVER" "$SQLUSER" "$SQLPASSWORD"
pop $0
pop $0
detailprint $0
detailprint $0
pop $0
pop $0
detailprint $0
detailprint $0
MSSQL_OLEDB::SQL_GetError /NOUNLOAD
MSSQL_OLEDB::SQL_GetError
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_Execute /NOUNLOAD "$SQLQUERY"
MSSQL_OLEDB::SQL_Execute "$SQLQUERY"
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError /NOUNLOAD
MSSQL_OLEDB::SQL_GetError
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow /NOUNLOAD
MSSQL_OLEDB::SQL_GetRow
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow /NOUNLOAD
MSSQL_OLEDB::SQL_GetRow
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError /NOUNLOAD
MSSQL_OLEDB::SQL_GetError
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Line 124: Line 143:
setoutpath $PLUGINSDIR
setoutpath $PLUGINSDIR
FILE test.sql
FILE test.sql
MSSQL_OLEDB::SQL_ExecuteScript /NOUNLOAD "$PLUGINSDIR\test.sql"
MSSQL_OLEDB::SQL_ExecuteScript "$PLUGINSDIR\test.sql"
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError /NOUNLOAD
MSSQL_OLEDB::SQL_GetError
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow /NOUNLOAD
MSSQL_OLEDB::SQL_GetRow
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow /NOUNLOAD
MSSQL_OLEDB::SQL_GetRow
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError /NOUNLOAD
MSSQL_OLEDB::SQL_GetError
Pop $0
Pop $0
DetailPrint $0
DetailPrint $0

Latest revision as of 07:43, 24 July 2010

Author: sgiusto@mmpoint.it (talk, contrib)


Download

Version 2.x: (new plugin API, distinct versions for NON-Unicode and Unicode builds of NSIS)
Mssql_oledb2.zip (570 KB)

Version 1.x: (old plugin API, limited support to Unicode scripts)
MSSQL_OLEDB.zip (73 KB)

Description

The MSSQL OLEDB plugin for NSIS provides some functions to add MSSQL interoperability within an install script

Version: 1.0 12th March 2007.

  • First Release

Version: 1.1 20th March 2007.

  • Fixed bug in DllMain under Windows 2000

Version: 1.2 29th March 2007.

  • Added SQL_ExecuteScript function

Version: 1.3 24th May 2007.

  • Fixed a bug in Data Column Binding causing data truncation in rowsets

Version: 1.4 11th Sept 2007.

  • Added support for Unicode SQL scripts in SQL_ExecuteScript function

Version: 2.0 11th April 2009.

  • Added support for new plugin api.
  • Added unicode version (Unicode scripts support is available only in unicode version from now on).
  • Script length is only limited by memory

Version: 2.0.1 1st August 2009.

  • Fixed an allocation bug. Global variables were not set to null after deletion in SQL_Logout function.

Supported on: Windows NT, Windows 2000, Windows XP,Vista,Win2k3,Win2k8,Seven.

Notes

  • MSSQL_OLEDB.dll is the standard (non Unicode) version of the plugin
  • UMSSQL_OLEDB.dll is the Unicode version of the plugin
  • To execute Unicode scripts the Unicode version of NSIS and the Unicode version of the plugin MUST be used.

Functions

SQL_Logon

MSSQL_OLEDB::SQL_Logon <server> <user> <password>
Logs on a SQL Server
<server> - Network name of SQL Server to log on
<user> - User (leave blank to use windows authentication)
<password> - Password
Returns
  • "0" Success, "1" Failure
  • A Message string

SQL_Execute

MSSQL_OLEDB::SQL_Execute <query>
Excecutes a SQL query
<query> - SQL query to execute
Returns
  • "0" Success, "1" Failure
  • A message string

SQL_ExecuteScript

MSSQL_OLEDB::SQL_ExecuteScript <scriptfile>
Excecutes a SQL query contained in a file
<scriptfile> - Path to file containing the script to execute
Returns
  • "0" Success, "1" Failure
  • A message string

SQL_GetRow

MSSQL_OLEDB::SQL_GetRow
Retrieves a row of data from the SQL server
Returns
  • "0" Success, "1" Failure, "2" No more data to read
  • A string containing the row of data (each column is separated by a '|' char). A message in case if error or no more data

SQL_GetError

MSSQL_OLEDB::SQL_GetError
Retrieves last error message generated by SQL Server. Call this function after a failure to get SQL state, native error code and message
Returns
  • "0" Success
  • A string containing the error

SQL_Logout

MSSQL_OLEDB::SQL_Logout

Deallocates memory used by dll and logs out of SQL server.

Usage Example

detailprint "Loggin on to SQL server $SQLSERVER"
MSSQL_OLEDB::SQL_Logon "$SQLSERVER" "$SQLUSER" "$SQLPASSWORD"
pop $0
detailprint $0
pop $0
detailprint $0
MSSQL_OLEDB::SQL_GetError
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_Execute "$SQLQUERY"
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
setoutpath $PLUGINSDIR
FILE test.sql
MSSQL_OLEDB::SQL_ExecuteScript "$PLUGINSDIR\test.sql"
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetRow
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_GetError
Pop $0
DetailPrint $0
Pop $0
DetailPrint $0
MSSQL_OLEDB::SQL_Logout

Credits

Written by Stefano Giusto [sgiusto@mmpoint.it]