The Engines.ODBC object provides access to the ODBC APIs.
The following example prints out the data source in the Debug Window.
var odbc = 0;
function onRefresh()
{
if (!odbc)
{
// Set the connection string
var odbc = Engines.ODBC.newDataSource("Provider=sqloledb;
Data Source=myServerAddress;Initial Catalog=myDataBase;
User Id=myUsername;Password=myPassword");
// Or, in case of Active Directory:
// var odbc = Engines.ODBC.newDataSource("Provider=sqloledb;
// Data Source=myServerAddress;Initial Catalog=myDataBase;
// Integrated Security=SSPI;");
}
// If connection to the database is successful, proceed with the query
if (odbc.connect ())
{
// Set up the database object with a query
odbc.setQuery("SELECT * FROM Production.Product
WHERE ProductID < 300");
// Or, for a stored procedure:
// odbc.setQuery( "EXEC dbo.uspGetEmployeeManagers 6" );
// Send the query to the database
if (odbc.sendQuery ())
{
// If the query is successfully sent, get the response object
// in XML format
var query_resp = odbc.response.xml;
// Print out the XML data in Debug Window
trace( query_resp );
}
// Disconnect from the database
odbc.disconnect ();
}
// Return the XML data for Klipfolio Dashboard to parse using
// stylesheet settings
return Engines.Data.process (query_resp);
}
Stylesheet Format
The returned XML is formatted z:row tags. Each row contains the list of columns as attributes within the z:row tag. The Klip's <style> block must be organized in the following manner in order for the returned XML data to be parsed:
<style>
z:row::attribute( columnHeaderName ) {
...
}
z:row::attribute( columnHeaderName ) {
...
}
z:row {
type: item;
definition: all;
}
</style>
The order of the style entries is important. The item definition must follow the entry definitions.
See also:
How-to article on
developing an ODBC Klip.
| Nested Object Summary | |
<static class> |
Engines.ODBC.ODBCResponse |
| Properties Summary | |
Engines.ODBC.ODBCResponse |
response
|
| Function Summary | |
function
|
connect()
|
boolean
|
disconnect()
|
String
|
getLastError()
|
function
|
newDataSource( <String> connectionstring )
|
boolean
|
sendQuery()
|
function
|
setQuery( <String> query )
|
| Properties Detail |
response
Engines.ODBC.ODBCResponse response
| Function Detail |
connect
function connect()
-
Returns:
-
true on success; otherwise false
disconnect
boolean disconnect()
-
Returns:
-
true on success; otherwise false
getLastError
String getLastError()
Example:
var odbc = Engines.ODBC.newDataSource (..);
if (!odbc.connect ()) {
alert (odbc.getLastError ());
}
Since:
5.3
-
Returns:
-
the description of the last error
newDataSource
function newDataSource( <String> connectionstring )
-
Parameters:
connectionstring - semicolon-separated keyword=value pairs for a given ODBC driver
sendQuery
boolean sendQuery()
-
Returns:
-
true on success; otherwise false
setQuery
function setQuery( <String> query )
-
Parameters:
query - query string passed to the ODBC driver
|
Klipfolio Dashboard 5 API | ||||||||
| PREV OBJECT NEXT OBJECT | FRAMES NO FRAMES | ||||||||
| SUMMARY: PROPERTY | FUNCTION | DETAIL: PROPERTY | FUNCTION | ||||||||
© 2010 Klipfolio Inc. All Rights Reserved.