VS:DBSQLExecute: Difference between revisions

From Vectorworks Developer
Jump to navigation Jump to search
No edit summary
No edit summary
 
Line 10: Line 10:
<def>
<def>
<funcDef lang="vs">
<funcDef lang="vs">
FUNCTION DBSQLExecute(database:STRING; username:STRING; password:STRING; SQLQuery:DYNARRAY[] of CHAR; VAR outColumnCnt:LONGINT; VAR outResultSetInst:LONGINT) : BOOLEAN;
FUNCTION DBSQLExecute(database:STRING; SQLQuery:DYNARRAY[] of CHAR; VAR outColumnCnt:LONGINT; VAR outResultSetInst:LONGINT) : BOOLEAN;
</funcDef>
</funcDef>
<funcDef lang="py">
<funcDef lang="py">
def vs.DBSQLExecute(database, username, password, SQLQuery):
def vs.DBSQLExecute(database, SQLQuery):
     return (BOOLEAN, outColumnCnt, outResultSetInst)
     return (BOOLEAN, outColumnCnt, outResultSetInst)
</funcDef>
</funcDef>
Line 25: Line 25:
STRING
STRING
</line>
</line>
<line>
username
STRING
</line>
<line>
password
STRING
</line>


<line>
<line>

Latest revision as of 12:31, 8 November 2014

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

Description

Executes a SQL in the specified database connected to the current document. Note! The resultSetInstance have to be deleted with call to 'DBSQLExecuteDelete'

FUNCTION DBSQLExecute(
database :STRING;
SQLQuery :DYNARRAY[] of CHAR;
VAR outColumnCnt :LONGINT;
VAR outResultSetInst :LONGINT) : BOOLEAN;
def vs.DBSQLExecute(database, SQLQuery):
    return (BOOLEAN, outColumnCnt, outResultSetInst)

Parameters

database STRING
SQLQuery DYNARRAY[] of CHAR
outColumnCnt LONGINT
outResultSetInst LONGINT

Example

PROCEDURE Test;
VAR
	res : BOOLEAN;
	colCnt, resSetInst, colIndex, rowIndex : LONGINT;
	colName, colValue : DYNARRAY [] OF CHAR;
BEGIN
	res := DBSQLExecuteDSN( 'My Building', '', '', 'SELECT * FROM Spaces', colCnt, resSetInst );
	AlrtDialog( Concat( 'Execute: res=', res, ' colCnt=', colCnt, ' resSetInst=', resSetInst ) );

	rowIndex := 1;
	REPEAT
		FOR colIndex := 1 TO colCnt DO BEGIN
			res := DBSQLExecuteGet( resSetInst, colIndex, colName, colValue );

			AlrtDialog( Concat( 'Result: row=', rowIndex, ' col=', colIndex, ' colName=', colName, ' colValue=', colValue ) );
		END;

		rowIndex  := rowIndex  + 1;
	UNTIL NOT DBSQLExecuteNext( resSetInst );

	DBSQLExecuteDelete( resSetInst );
END;
RUN(Test);

Python

def Test():
	res, colCnt, resSetInst = vs.DBSQLExecuteDSN( 'My Building', '', '', 'SELECT * FROM Spaces' )
	vs.AlrtDialog( vs.Concat( 'Execute: res=', res, ' colCnt=', colCnt, ' resSetInst=', resSetInst ) )
	
	rowIndex = 1
	dbNext = True
	while dbNext:
		for colIndex in range(1, colCnt):
			res, colName, colValue = vs.DBSQLExecuteGet( resSetInst, colIndex )
			vs.AlrtDialog( Concat( 'Result: row=', rowIndex, ' col=', colIndex, ' colName=', colName, ' colValue=', colValue ) )

		rowIndex  = rowIndex  + 1
		dbNext = vs.DBSQLExecuteNext( resSetInst )

	vs.DBSQLExecuteDelete( resSetInst )

Test()

Version

Availability: from Vectorworks 2011