Klipfolio Dashboard API

Object Engines.ODBC

Object
   |
   +--Klip
         |
         +--Engines
               |
               +--Engines.ODBC

Advanced Feature This object is an advanced feature that is only available in the licensed, commercial version of Klipfolio Dashboard. Contact Klipfolio for further details.

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 );
 		}
		// If sending of the query to the database fails, output the error
		else {
			traceln( "Could not send the query: " + odbc.getLastError() );
			// Disconnect from the database
			odbc.disconnect ();
		}

		// Disconnect from the database
 		odbc.disconnect ();
 	}
	// If connection to the database fails, 
	// output the error from the ODBC driver in the Debug Window
	else {
		traceln( "Could not connect to database: " + odbc.getLastError() );

		// 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
 integer commandtimeout
          Advanced Feature The amount of time before the connection times out in seconds.
 Engines.ODBC.ODBCResponse response
          Advanced Feature The response instance.
   
Function Summary
 function connect()
           Advanced Feature Connects to a specified database.
 boolean disconnect()
           Advanced Feature Disconnects from a specified database.
 String getLastError()
           Advanced Feature Gets the description of the most recent error.
 function newDataSource( <String> connectionstring )
           Advanced Feature Configures a new data source.
 boolean sendQuery()
           Advanced Feature Sends a query to the database.
 function setQuery( <String> query )
           Advanced Feature Sets up the database object with a query.

Properties Detail

commandtimeout

integer commandtimeout

response

Engines.ODBC.ODBCResponse response

Function Detail

connect

function connect()

disconnect

boolean disconnect()

getLastError

String getLastError()

newDataSource

function newDataSource( <String> connectionstring )

sendQuery

boolean sendQuery()

setQuery

function setQuery( <String> query )

Klipfolio Dashboard API

© 2011 Klipfolio Inc. All Rights Reserved.