publish
plugins.it2be_data.IDDbf info


Servoy Methods Summary
Array<Array<Object>> getArray( String, Boolean )
Array<Array<Object>> getArray( String )
JSDataSet getDataSet( String, Boolean )
JSDataSet getDataSet( String )
void overrideTextFieldLimit( Number )
String write( String, Array<Object>, Object, Boolean )
String write( String, Object )
String write( String, Array<Object>, Object )
String writeArray( String, Array<Object>, Array<Array<Object>>, Boolean )
String writeArray( String, Array<Object>, Array<Array<Object>> )


Servoy Methods Details


getArray
Array<Array<Object>>  getArray( String, Boolean )
Read a DBF file and return a 2D Array. The showHeader parameter defaults to true.
Parameters
String  filePath  the file path
Boolean  showHeader  the show header

Returns
Array<Array<Object>>  array Object[][]

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the showHeader parameter set to true the first row will will show in the result

// create a dataset from the file
// the showHeader parameter is set to false by default
set = plugins.it2be_data.dbf().getDataSet( filePath);

// create a two dimensional array from the file
// the showHeader parameter is set to true by default
array = plugins.it2be_data.dbf().getArray( filePath, true);

// when the dataset is NOT empty
if (!set.getMaxRowIndex()) {
var message = "";

application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

if (array) {
var message = "";

application.output("array.length = " + array.length);

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getArray
Array<Array<Object>>  getArray( String )
Read a DBF file and return a 2D Array. The showHeader parameter defaults to true.
Parameters
String  filePath  the file path

Returns
Array<Array<Object>>  array Object[][]

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the showHeader parameter set to true the first row will will show in the result

// create a dataset from the file
// the showHeader parameter is set to false by default
set = plugins.it2be_data.dbf().getDataSet( filePath);

// create a two dimensional array from the file
// the showHeader parameter is set to true by default
array = plugins.it2be_data.dbf().getArray( filePath, true);

// when the dataset is NOT empty
if (!set.getMaxRowIndex()) {
var message = "";

application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

if (array) {
var message = "";

application.output("array.length = " + array.length);

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getDataSet
JSDataSet  getDataSet( String, Boolean )
Read a DBF file and return a JSDataSet. The showHeader parameter defaults to false.
Parameters
String  filePath  the file path
Boolean  showHeader  the show header

Returns
JSDataSet  set JSDataSet

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the showHeader parameter set to true the first row will will show in the result

// create a dataset from the file
// the showHeader parameter is set to false by default
set = plugins.it2be_data.dbf().getDataSet( filePath);

// create a two dimensional array from the file
// the showHeader parameter is set to true by default
array = plugins.it2be_data.dbf().getArray( filePath, true);

// when the dataset is NOT empty
if (!set.getMaxRowIndex()) {
var message = "";

application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

if (array) {
var message = "";

application.output("array.length = " + array.length);

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


getDataSet
JSDataSet  getDataSet( String )
Read a DBF file and return a JSDataSet. The showHeader parameter defaults to false.
Parameters
String  filePath  the file path

Returns
JSDataSet  set JSDataSet

Supported Clients
SmartClient, WebClient, NGClient

Sample
// set the name of the file
var file = plugins.file.showFileOpenDialog();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
var set = null;
var array = null;

// with the showHeader parameter set to true the first row will will show in the result

// create a dataset from the file
// the showHeader parameter is set to false by default
set = plugins.it2be_data.dbf().getDataSet( filePath);

// create a two dimensional array from the file
// the showHeader parameter is set to true by default
array = plugins.it2be_data.dbf().getArray( filePath, true);

// when the dataset is NOT empty
if (!set.getMaxRowIndex()) {
var message = "";

application.output("set.getMaxRowIndex() = " + set.getMaxRowIndex());

// because the set is a 'standard' JSDataSet all the functions and properties
// we can use the Database Manager to retrieve the column count and column names
var columncount = set.getMaxColumnIndex();

// limit the number of columns we show to 5 when columncount > 5
// 5 is an arbitrary value to limit the width of the dialog
columncount = (columncount > 5) ? 5 : columncount;

// loop through the columns
for (var i = 1 ; i <= columncount ; i++) {
// retreive the names
message += set.getColumnName(i) + "::";
}
message += "\n";

// JSDataSet.sort(number, boolean) is also valid
set.sort(1, false);

var rowcount = (set.getMaxRowIndex() > 5) ? 5 : set.getMaxRowIndex();

// loop through the rows of the JSDataSet
// REMARK: the JSDataSet starts counting at 1 instead of 0
for (var i = 1 ; i <= rowcount ; i++) {
// loop through the columns
for (var ii = 1 ; ii <= columncount ; ii++) {
// and retreive the column values
message += set.getValue(i, ii) + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("JSDataSet", message);
}
} else {
// output to the debugger to show there is NO result
application.output("JSDataSet = null");
}

if (array) {
var message = "";

application.output("array.length = " + array.length);

// limit the column and row count for display purposes
var columncount = (array[0].length > 5) ? 5 : array[0].length;
var rowcount = (array.length > 5) ? 5 : array.length;

// loop through the 3D array
// REMARK: an array starts at index 0
for (var i = 0 ; i < rowcount ; i++) {
for (var ii = 0 ; ii < columncount ; ii++) {
message += array[i][ii] + "::";
}
message += "\n";
}

// show the result
if (message) {
plugins.dialogs.showInfoDialog("Array", message);
}
} else {
// output to the debugger to show there is NO result
application.output("Array = null");
}
}


overrideTextFieldLimit
void  overrideTextFieldLimit( Number )
Set the maximum length of a text field to a value higher than 50 (minimum = default = 50).
Parameters
Number  limit  the text field limit

Returns
void  

Supported Clients
SmartClient, WebClient, NGClient


write
String  write( String, Array<Object>, Object, Boolean )
Write a Dbf file.
Parameters
String  filePath  the file path
Array<Object>  header  the header
Object  set  the dataset
Boolean  overwrite  the overwrite

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 1000);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.dbf().writeArray( filePath, header, selection);
// we won't use the 'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.dbf().write( filePath, header, dataset);

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


write
String  write( String, Object )
Write a Dbf file.
Parameters
String  filePath  the file path
Object  set

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 1000);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.dbf().writeArray( filePath, header, selection);
// we won't use the 'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.dbf().write( filePath, header, dataset);

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


write
String  write( String, Array<Object>, Object )
Write a Dbf file.
Parameters
String  filePath  the file path
Array<Object>  header  the header
Object  set

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 1000);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.dbf().writeArray( filePath, header, selection);
// we won't use the 'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.dbf().write( filePath, header, dataset);

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


writeArray
String  writeArray( String, Array<Object>, Array<Array<Object>>, Boolean )
Write a Dbf file.
Parameters
String  filePath  the file path
Array<Object>  header  the header
Array<Array<Object>>  array  the array
Boolean  overwrite  the overwrite

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 1000);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.dbf().writeArray( filePath, header, selection);
// we won't use the 'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.dbf().write( filePath, header, dataset);

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}


writeArray
String  writeArray( String, Array<Object>, Array<Array<Object>> )
Write a Dbf file.
Parameters
String  filePath  the file path
Array<Object>  header  the header
Array<Array<Object>>  array  the array

Returns
String  fileName String

Supported Clients
SmartClient, WebClient, NGClient

Sample
// Get a dataset based on a query on the example (crm) database
// and it2be_companies/contacts tables
var query = "SELECT c.firstname, c.lastname, o.company_name, o.description FROM it2be_contacts AS c, it2be_companies AS o WHERE c.it2be_companiesid=o.it2be_companiesid";
var dataset = databaseManager.getDataSetByQuery(controller.getServerName(), query, null, 1000);

// stop executing this method when the dataset is empty
// and show an error dialog
if (!dataset.getMaxRowIndex()) {
plugins.dialogs.showErrorDialog("Error.", "There are no records!", "OK");

Return;
}

// set the name of the file
var file = plugins.file.showFileSaveDialog();

// get the name of the operating system to know how to execute the,
// to the filetype attached,application
var osname = application.getOSName();

// check that we really selected a file
// if not ignore the rest of the code
if (file) {
var filePath = file.getAbsoluteFile();
// create the header as a 2 dimentional array
// it is also possible to create a 3 dimensional array (see example dbf)
// in that case the rest of the data is ignored when not creating a dbf file
var header = ["firstname","lastname","company","description"];

// we can use either a 2D array or a dataset for input
// you would typically use a 2D array from data you can not retreive from the database
// in the below example we will create a 2D array from a dataset
// just to show you how to do it
var selection = new Array();

for (var i = 1 ; i <= dataset.getMaxRowIndex() ; i++) {
var row = dataset.getRowAsArray(i);

selection[i - 1] = row;
}

// write the file
// filePath = plugins.it2be_data.dbf().writeArray( filePath, header, selection);
// we won't use the 'selection' array since a dataset can be used without creating an array
filePath = plugins.it2be_data.dbf().write( filePath, header, dataset);

// open the data in the (to the filetype attached) application
// checking the os needs to be done via evaluation of a string
// you can also use the tools plugin that will give you an integer
if (osname.indexOf("Mac") > -1) {
// mac os x
application.executeProgram("open", filePath);
} else if (osname.indexOf("Windows") > -1) {
// windows
application.executeProgram("rundll32", "url.dll,FileProtocolHandler", filePath);
} else {
// linux etc. would love to know how to do this!
}
}