Friday, April 10, 2015

Dexterity - template for executing SQL and getting a result

{ Clean Code approach to pass through SQL }

pragma(disable warning LiteralStringUsed);
local long sqlConnection, status;
local text SQL;

local long numRecords;

if SQL_Connect(sqlConnection) <> OKAY then
throw SQL_EXCEPTION, 0, "Connection to SQL has not been established.";
end if;

SQL = " USE " +  trim('Intercompany ID' of globals);
SQL = SQL + " SELECT COUNT(*) FROM " + physicalname(table myTable);
debug SQL;

if SQL_Execute(sqlConnection, SQL) = OKAY then
status = SQL_FetchNext(sqlConnection);
status = SQL_GetData(sqlConnection, 1, numRecords);
call SQLErrorHandler, sqlConnection;
end if;

status = SQL_Terminate(sqlConnection);

pragma(enable warning LiteralStringUsed);

No comments:

Post a Comment

There was an error in this gadget