Trouble with ConvertToDataSet

hi all, im having troubles using the ConvertToDataSet sentence.

I want to get the column names of a record and the data inside of the columns and show them in a form i create on the fly. To do this, i put the column names in an array and then the value in the same array but another row like a matrix.

Now, the problem i have is that when i use the ConvertToDataSet sentence with an array with the dataprovider names as a parameter, it shows an error saying the index of the array is out of bounds. This only happens if i have 2 dataprovider names, if i have 1, it is OK, but the values are not shown only the columns.

Also, i know i have the values in the array, i debugged it.

this is the code i use:

{
	history.removeForm('p')
	solutionModel.removeForm('p')
	
	var tabla = databaseManager.getTable( currentcontroller.getServerName(),  currentcontroller.getTableName())
	var a = new Array()
	a = tabla.getColumnNames()
	var tope = a.length
	
	var val
	for (var i = 0; i < tope-1 ; i++)
	{	
		val = currentcontroller.getDataProviderValue(a[1,i])
		a[i,1] = val
	}
	var b = new Array ("Field","Value")
	var ds = databaseManager.convertToDataSet(a, b)
	var uri = ds.createDataSource('test', [DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.TEXT])
	
	var jsform = solutionModel.newForm('p', uri, null, true, 300, 300);
	jsform.newField("Field",SM_DISPLAYTYPE.TEXT_FIELD,100,100,100,20)
	jsform.newField("Value",SM_DISPLAYTYPE.TEXT_FIELD,200,200,100,20)
    
	forms.p.controller.show()
}

Hope you understand what i am asking for

Thank you in advance

There was a bug when using arrays and column names, in servoy 4.1.1 it should be solved.

For now you could use a dataset instead of an array.

Hi saneke… thanks for the reply… the thing is that im already using 4.1.1…

However, i tried to use a dataset instead of an array and get an error (obvioulsy im making some mistake and dont know how to solve it)

should this code be the same that the code above??

	history.removeForm('p')
	solutionModel.removeForm('p')
	
	var tabla = databaseManager.getTable( currentcontroller.getServerName(),  currentcontroller.getTableName())
	var a = new Array()
	a = tabla.getColumnNames()
	var tope = a.length
	var b = new Array ("Field","Value")
	
	var ds = databaseManager.createEmptyDataSet( tope,  b)
	var val, i
	
	for (i = 0; i< tope-1; i++)
	{
		ds.setValue(i+1, 1, a[i])
		val = currentcontroller.getDataProviderValue(a[i])
		ds.setValue(i,2,val)
	}
	
	var uri = ds.createDataSource('test', [DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.TEXT])
	
	var jsform = solutionModel.newForm('p', uri, null, true, 300, 300);
	jsform.newField("Field",SM_DISPLAYTYPE.TEXT_FIELD,100,100,100,20)
	jsform.newField("Value",SM_DISPLAYTYPE.TEXT_FIELD,200,200,100,20)
    
	forms.p.controller.show()

i get this error:

java.sql.SQLException: Unexpected token: in statement [create table “TEMP_4_2f54d56e-933a-490b-9736-d392230c1b81” (“_sv_rowid” integer generated by default as identity (start with 1), Field varchar(2147483647) default null, “”]

java.lang.RuntimeException: java.sql.SQLException: Unexpected token: in statement [create table “TEMP_4_2f54d56e-933a-490b-9736-d392230c1b81” (“_sv_rowid” integer generated by default as identity (start with 1), Field varchar(2147483647) default null, “”]

I made a sample that works:

	history.removeForm('p')
	solutionModel.removeForm('p')
	
	var tabla = databaseManager.getTable( currentcontroller.getServerName(),  currentcontroller.getTableName())
	var a = new Array()
	a = tabla.getColumnNames()
	var ds = databaseManager.createEmptyDataSet()
	
	ds.addColumn('Field')
	ds.addColumn('Value')
	for (var i = 0; i < a.length; i++) 
	{
		ds.addRow([a[i],''])
	}
	
	var uri = ds.createDataSource('test', [DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.TEXT])
	
	var jsform = solutionModel.newForm('p', uri, null, true, 300, 300);
	jsform.newField("Field",SM_DISPLAYTYPE.TEXT_FIELD,100,100,100,20)
	jsform.newField("Value",SM_DISPLAYTYPE.TEXT_FIELD,200,200,100,20)
	
	forms.p.controller.show()

thank you sanneke, that gives no errors, but still i cant find the way to show the data inside the columns… i tried doing this

 for (var i = 0; i < a.length; i++) 
   {
      ds.addRow([a[i],''])
      var val = currentcontroller.getDataProviderValue(a[i])
      ds.setValue(a[i],'Value',val)
   }

but when i go to the form, the field ‘Value’ is null in every record. Any ideas?

Andres,

Have a good look at what ds.setValue expects (see the sample code)
Try this:

 for (var i = 0; i < a.length; i++)
{
     ds.addRow([a[i],currentcontroller.getDataProviderValue(a[i])])
}

I tried your method where you reported the sql expection, I could not reproduce this.
Can you (re)create a method that would create this error and attach it to a case in our support system?

Rob

i could solve it… the code is:

  history.removeForm('p')
   solutionModel.removeForm('p')
   
   var tabla = databaseManager.getTable( currentcontroller.getServerName(),  currentcontroller.getTableName())
   var a = new Array()
   a = tabla.getColumnNames()
   var ds = databaseManager.createEmptyDataSet()
   
   ds.addColumn('Field')
   ds.addColumn('Value')
   
   for (var i = 0; i < a.length; i++) 
   {
      ds.addRow([a[i],''])
      var val = currentcontroller.getDataProviderValue(a[i])
      ds.setValue(i+1,2,val)
   }
   var uri = ds.createDataSource('test', [DM_COLUMNTYPE.TEXT, DM_COLUMNTYPE.TEXT])
   
   var jsform = solutionModel.newForm('p', uri, null, true, 300, 300);
   jsform.newField("Field",SM_DISPLAYTYPE.TEXT_FIELD,100,100,100,20)
   jsform.newField("Value",SM_DISPLAYTYPE.TEXT_FIELD,200,200,100,20)
   
   forms.p.controller.show()

the arguments of steValue were wrong… now this works…

thank you for your help… i will try to recreate the exception again and file a case