Hi Chris,
Let me explain the real issue behind my question in case there is another way reach my goal. But first let me preface that by saying I am new to C# and .net and I am at the beginning stages of creating a Web API for an existing PowerBuilder application.
In my application I make extensive use of dynamically created datastores. I have found an easy enough way to perform the data retrieval for these datastores. But as I am using the sqlca.SyntaxFromSQL method to create the datastore I cannot decouple the application from the database. I would like to find a way around this.
In PoweerBuilder:
global type uo_datastore from datastore
public function boolean build(string as_sqlselect)
is_SqlSelect = as_sqlselect
ls_Syntax = sqlca.SyntaxFromSQL( as_SqlSelect, '', ls_error )
this.Create( ls_Syntax, ls_error )
end function
public funtion long retrieve()
ls_url = inv_HttpClient.of_get_url('D_Datastore','Retrive') + is_SqlSelect
li_return = inv_HttpClient.sendrequest("Get", ls_url)
inv_HttpClient.getresponsebody(ls_json)
this.importjson(ls_json)
end function
In Web API:
public class D_Datastore
{
public IDataStore Retrieve(String sqlSelect)
{
var dwMeta = DwMeta.CreateFromSql(sqlSelect, _dataContext);
var ds = DataStore.Create(dwMeta, _dataContext);
ds.Retrieve()
return ds;
}
}
And this works if my application has a connection to the database in order to get the datawindow syntax. But as mentioned I would like to decouple the application from the database entirely.
My first idea, which prompted my question, was to obtain the column names and data types from the web api:
public IDataStore RetrieveInfo(String sqlSelect)
{
var dwMeta = DwMeta.CreateFromSql(sqlSelect, _dataContext);
IDataStore ds = DataStore.Create(dwMeta, _dataContext);
_d_sql_info = new DataStore<D_SQL_Info>(_dataContext);
int columnCount = int.Parse(ds.Describe("Datawindow.Column.Count"));
for (int colNo = 1; colNo <= columnCount ; colNo++)
{
_d_sql_info.Add(new D_SQL_Info()) ;
_d_sql_info.SetItem(colNo - 1, "Column_No", colNo);
string colName = ds.Describe("#" + (colNo - 1) + ".Name");
string colType = ds.Describe(colName + ".ColType");
_d_sql_info.SetItem(colNo - 1, "Column_Name", colName);
_d_sql_info.SetItem(colNo - 1, "Column_Type", colType);
}
return (DataStore)_d_sql_info;
}
[DataWindow("d_sql_info", DwStyle.Grid)]
public class D_SQL_Info
{
[DwColumn("column_no")]
public int Column_No { get; set; }
[DwColumn("column_name")]
public string Column_Name { get; set; }
[DwColumn("column_type")]
public string Column_Type { get; set; }
public static implicit operator D_SQL_Info(DataStore<D_SQL_Info> v)
{
throw new NotImplementedException();
}
}
...and create the Datawindow syntax from the column info returned. But since this doesn't yield the string length or the decimal precision, is there any other method of creating a datawindow in PowerBuilder with only a Select statement; such that the data types will match what would have been returned by the database and now the web api?
Thanks again.