* Add Data Abstract classes and demo (read-only for the moment)

This commit is contained in:
michael 2018-12-23 11:16:40 +00:00
parent 16e88a1a38
commit b8e3bcccaf
10 changed files with 6138 additions and 0 deletions

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,665 @@
//----------------------------------------------------------------------------//
// This unit was automatically generated by the RemObjects SDK after reading //
// the RODL file associated with this project . //
// //
// Do not modify this unit manually, or your changes will be lost when this //
// unit is regenerated the next time you compile the project. //
//----------------------------------------------------------------------------//
/* This codegen depends on RemObjectsSDK.js
* Usage:
* var Channel = new RemObjects.SDK.HTTPClientChannel("http://localhost:8099/JSON");
* var Message = new RemObjects.SDK.JSONMessage();
* var Service = new NewService(Channel, Message);
* Service.Sum(1, 2,
* function(result) {
* alert(result);
* },
* function(msg) {alert(msg.getErrorMessage())}
* );
*
*/
__namespace = this;
if ("RemObjects.DataAbstract.Server" != "") {
var parts = "RemObjects.DataAbstract.Server".split(".");
var current = this;
for (var i = 0; i < parts.length; i++) {
current[parts[i]] = current[parts[i]] || {};
current = current[parts[i]];
};
__namespace = current;
};
// Enum: ColumnSortDirection
__namespace.ColumnSortDirection = function ColumnSortDirection() {
this.value = null;
};
__namespace.ColumnSortDirection.prototype = new RemObjects.SDK.ROEnumType();
__namespace.ColumnSortDirection.prototype.enumValues = [
"Ascending",
"Descending"
];
__namespace.ColumnSortDirection.prototype.constructor = __namespace.ColumnSortDirection;
RemObjects.SDK.RTTI["ColumnSortDirection"] = __namespace.ColumnSortDirection;
// Enum: ScriptExceptionType
__namespace.ScriptExceptionType = function ScriptExceptionType() {
this.value = null;
};
__namespace.ScriptExceptionType.prototype = new RemObjects.SDK.ROEnumType();
__namespace.ScriptExceptionType.prototype.enumValues = [
"ParserError",
"RuntimeError",
"Fail",
"UnexpectedException"
];
__namespace.ScriptExceptionType.prototype.constructor = __namespace.ScriptExceptionType;
RemObjects.SDK.RTTI["ScriptExceptionType"] = __namespace.ScriptExceptionType;
// Struct: DataParameter
__namespace.DataParameter = function DataParameter() {
this.Name = {dataType : "Utf8String", value : null};
this.Value = {dataType : "Variant", value : null};
};
__namespace.DataParameter.prototype = new RemObjects.SDK.ROStructType();
__namespace.DataParameter.prototype.constructor = __namespace.DataParameter;
RemObjects.SDK.RTTI["DataParameter"] = __namespace.DataParameter;
// Struct: TableRequestInfo
__namespace.TableRequestInfo = function TableRequestInfo() {
this.IncludeSchema = {dataType : "Boolean", value : null};
this.MaxRecords = {dataType : "Integer", value : null};
this.Parameters = {dataType : "DataParameterArray", value : null};
this.UserFilter = {dataType : "Utf8String", value : null};
};
__namespace.TableRequestInfo.prototype = new RemObjects.SDK.ROStructType();
__namespace.TableRequestInfo.prototype.constructor = __namespace.TableRequestInfo;
RemObjects.SDK.RTTI["TableRequestInfo"] = __namespace.TableRequestInfo;
// Struct: TableRequestInfoV6
__namespace.TableRequestInfoV6 = function TableRequestInfoV6() {
this.IncludeSchema = {dataType : "Boolean", value : null};
this.MaxRecords = {dataType : "Integer", value : null};
this.Parameters = {dataType : "DataParameterArray", value : null};
this.Sql = {dataType : "WideString", value : null};
this.UserFilter = {dataType : "Utf8String", value : null};
};
__namespace.TableRequestInfoV6.prototype = new RemObjects.SDK.ROStructType();
__namespace.TableRequestInfoV6.prototype.constructor = __namespace.TableRequestInfoV6;
RemObjects.SDK.RTTI["TableRequestInfoV6"] = __namespace.TableRequestInfoV6;
// Struct: TableRequestInfoV5
__namespace.TableRequestInfoV5 = function TableRequestInfoV5() {
this.DynamicSelectFieldNames = {dataType : "StringArray", value : null};
this.IncludeSchema = {dataType : "Boolean", value : null};
this.MaxRecords = {dataType : "Integer", value : null};
this.Parameters = {dataType : "DataParameterArray", value : null};
this.Sorting = {dataType : "ColumnSorting", value : null};
this.UserFilter = {dataType : "Utf8String", value : null};
this.WhereClause = {dataType : "Xml", value : null};
};
__namespace.TableRequestInfoV5.prototype = new RemObjects.SDK.ROStructType();
__namespace.TableRequestInfoV5.prototype.constructor = __namespace.TableRequestInfoV5;
RemObjects.SDK.RTTI["TableRequestInfoV5"] = __namespace.TableRequestInfoV5;
// Struct: UserInfo
__namespace.UserInfo = function UserInfo() {
this.Attributes = {dataType : "VariantArray", value : null};
this.Privileges = {dataType : "StringArray", value : null};
this.SessionID = {dataType : "Utf8String", value : null};
this.UserData = {dataType : "Binary", value : null};
this.UserID = {dataType : "Utf8String", value : null};
};
__namespace.UserInfo.prototype = new RemObjects.SDK.ROStructType();
__namespace.UserInfo.prototype.constructor = __namespace.UserInfo;
RemObjects.SDK.RTTI["UserInfo"] = __namespace.UserInfo;
// Struct: ColumnSorting
__namespace.ColumnSorting = function ColumnSorting() {
this.FieldName = {dataType : "Utf8String", value : null};
this.SortDirection = {dataType : "ColumnSortDirection", value : null};
};
__namespace.ColumnSorting.prototype = new RemObjects.SDK.ROStructType();
__namespace.ColumnSorting.prototype.constructor = __namespace.ColumnSorting;
RemObjects.SDK.RTTI["ColumnSorting"] = __namespace.ColumnSorting;
// Array: ColumnSortingArray
__namespace.ColumnSortingArray = function ColumnSortingArray() {
RemObjects.SDK.ROArrayType.call(this);
this.elementType = "ColumnSorting";
};
__namespace.ColumnSortingArray.prototype = new RemObjects.SDK.ROArrayType();
__namespace.ColumnSortingArray.prototype.constructor = __namespace.ColumnSortingArray;
RemObjects.SDK.RTTI["ColumnSortingArray"] = __namespace.ColumnSortingArray;
// Array: DataParameterArray
__namespace.DataParameterArray = function DataParameterArray() {
RemObjects.SDK.ROArrayType.call(this);
this.elementType = "DataParameter";
};
__namespace.DataParameterArray.prototype = new RemObjects.SDK.ROArrayType();
__namespace.DataParameterArray.prototype.constructor = __namespace.DataParameterArray;
RemObjects.SDK.RTTI["DataParameterArray"] = __namespace.DataParameterArray;
// Array: StringArray
__namespace.StringArray = function StringArray() {
RemObjects.SDK.ROArrayType.call(this);
this.elementType = "Utf8String";
};
__namespace.StringArray.prototype = new RemObjects.SDK.ROArrayType();
__namespace.StringArray.prototype.constructor = __namespace.StringArray;
RemObjects.SDK.RTTI["StringArray"] = __namespace.StringArray;
// Array: TableRequestInfoArray
__namespace.TableRequestInfoArray = function TableRequestInfoArray() {
RemObjects.SDK.ROArrayType.call(this);
this.elementType = "TableRequestInfo";
};
__namespace.TableRequestInfoArray.prototype = new RemObjects.SDK.ROArrayType();
__namespace.TableRequestInfoArray.prototype.constructor = __namespace.TableRequestInfoArray;
RemObjects.SDK.RTTI["TableRequestInfoArray"] = __namespace.TableRequestInfoArray;
// Array: VariantArray
__namespace.VariantArray = function VariantArray() {
RemObjects.SDK.ROArrayType.call(this);
this.elementType = "Variant";
};
__namespace.VariantArray.prototype = new RemObjects.SDK.ROArrayType();
__namespace.VariantArray.prototype.constructor = __namespace.VariantArray;
RemObjects.SDK.RTTI["VariantArray"] = __namespace.VariantArray;
// Exception: ScriptException
__namespace.ScriptException = function ScriptException(e) {
RemObjects.SDK.ROException.call(this, e);
this.fields.Line = {dataType : "Integer", value : null};
this.fields.Column = {dataType : "Integer", value : null};
this.fields.Event = {dataType : "Utf8String", value : null};
this.fields.InnerStackTrace = {dataType : "Utf8String", value : null};
this.fields.Type = {dataType : "ScriptExceptionType", value : null};
};
__namespace.ScriptException.prototype = new RemObjects.SDK.ROException();
RemObjects.SDK.RTTI["ScriptException"] = __namespace.ScriptException;
// Service: DataAbstractService
__namespace.DataAbstractService = function DataAbstractService(__channel, __message, __service_name) {
RemObjects.SDK.ROService.call(this, __channel, __message, __service_name);
this.fServiceName = this.fServiceName || __service_name || "DataAbstractService";
};
__namespace.DataAbstractService.prototype.GetSchema = function(
aFilter,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "GetSchema");
msg.write("aFilter", "Utf8String", aFilter);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Utf8String");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.GetData = function(
aTableNameArray,
aTableRequestInfoArray,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "GetData");
msg.write("aTableNameArray", "StringArray", aTableNameArray);
msg.write("aTableRequestInfoArray", "TableRequestInfoArray", aTableRequestInfoArray);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Binary");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.UpdateData = function(
aDelta,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "UpdateData");
msg.write("aDelta", "Binary", aDelta);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Binary");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.ExecuteCommand = function(
aCommandName,
aParameterArray,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "ExecuteCommand");
msg.write("aCommandName", "Utf8String", aCommandName);
msg.write("aParameterArray", "DataParameterArray", aParameterArray);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Integer");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.ExecuteCommandEx = function(
aCommandName,
aInputParameters,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "ExecuteCommandEx");
msg.write("aCommandName", "Utf8String", aCommandName);
msg.write("aInputParameters", "DataParameterArray", aInputParameters);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Integer");
var __aOutputParameters = __message.read("aOutputParameters", "DataParameterArray");
__success(
__result
,
__aOutputParameters
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.GetTableSchema = function(
aTableNameArray,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "GetTableSchema");
msg.write("aTableNameArray", "StringArray", aTableNameArray);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Utf8String");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.GetCommandSchema = function(
aCommandNameArray,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "GetCommandSchema");
msg.write("aCommandNameArray", "StringArray", aCommandNameArray);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Utf8String");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.SQLGetData = function(
aSQLText,
aIncludeSchema,
aMaxRecords,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "SQLGetData");
msg.write("aSQLText", "Utf8String", aSQLText);
msg.write("aIncludeSchema", "Boolean", aIncludeSchema);
msg.write("aMaxRecords", "Integer", aMaxRecords);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Binary");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.SQLGetDataEx = function(
aSQLText,
aIncludeSchema,
aMaxRecords,
aDynamicWhereXML,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "SQLGetDataEx");
msg.write("aSQLText", "Utf8String", aSQLText);
msg.write("aIncludeSchema", "Boolean", aIncludeSchema);
msg.write("aMaxRecords", "Integer", aMaxRecords);
msg.write("aDynamicWhereXML", "WideString", aDynamicWhereXML);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Binary");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.SQLExecuteCommand = function(
aSQLText,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "SQLExecuteCommand");
msg.write("aSQLText", "Utf8String", aSQLText);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Integer");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.SQLExecuteCommandEx = function(
aSQLText,
aDynamicWhereXML,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "SQLExecuteCommandEx");
msg.write("aSQLText", "Utf8String", aSQLText);
msg.write("aDynamicWhereXML", "WideString", aDynamicWhereXML);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Integer");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.GetDatasetScripts = function(
DatasetNames,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "GetDatasetScripts");
msg.write("DatasetNames", "Utf8String", DatasetNames);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Utf8String");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.RegisterForDataChangeNotification = function(
aTableName,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "RegisterForDataChangeNotification");
msg.write("aTableName", "Utf8String", aTableName);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
__success(
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.DataAbstractService.prototype.UnregisterForDataChangeNotification = function(
aTableName,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "UnregisterForDataChangeNotification");
msg.write("aTableName", "Utf8String", aTableName);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
__success(
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
// Service: BaseLoginService
__namespace.BaseLoginService = function BaseLoginService(__channel, __message, __service_name) {
RemObjects.SDK.ROService.call(this, __channel, __message, __service_name);
this.fServiceName = this.fServiceName || __service_name || "BaseLoginService";
};
__namespace.BaseLoginService.prototype.LoginEx = function(
aLoginString,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "LoginEx");
msg.write("aLoginString", "Utf8String", aLoginString);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Boolean");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.BaseLoginService.prototype.Logout = function(
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "Logout");
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
__success(
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
// Service: MultiDbLoginService
__namespace.MultiDbLoginService = function MultiDbLoginService(__channel, __message, __service_name) {
RemObjects.SDK.ROService.call(this, __channel, __message, __service_name);
this.fServiceName = this.fServiceName || __service_name || "MultiDbLoginService";
};
__namespace.MultiDbLoginService.prototype = new __namespace.BaseLoginService();
__namespace.MultiDbLoginService.prototype.Login = function(
aUserID,
aPassword,
aConnectionName,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "Login");
msg.write("aUserID", "Utf8String", aUserID);
msg.write("aPassword", "Utf8String", aPassword);
msg.write("aConnectionName", "Utf8String", aConnectionName);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Boolean");
var __aUserInfo = __message.read("aUserInfo", "UserInfo");
__success(
__result
,
__aUserInfo
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
// Service: MultiDbLoginServiceV5
__namespace.MultiDbLoginServiceV5 = function MultiDbLoginServiceV5(__channel, __message, __service_name) {
RemObjects.SDK.ROService.call(this, __channel, __message, __service_name);
this.fServiceName = this.fServiceName || __service_name || "MultiDbLoginServiceV5";
};
__namespace.MultiDbLoginServiceV5.prototype = new __namespace.MultiDbLoginService();
__namespace.MultiDbLoginServiceV5.prototype.GetConnectionNames = function(
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "GetConnectionNames");
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "StringArray");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
__namespace.MultiDbLoginServiceV5.prototype.GetDefaultConnectionName = function(
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "GetDefaultConnectionName");
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Utf8String");
__success(
__result
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
// Service: SimpleLoginService
__namespace.SimpleLoginService = function SimpleLoginService(__channel, __message, __service_name) {
RemObjects.SDK.ROService.call(this, __channel, __message, __service_name);
this.fServiceName = this.fServiceName || __service_name || "SimpleLoginService";
};
__namespace.SimpleLoginService.prototype = new __namespace.BaseLoginService();
__namespace.SimpleLoginService.prototype.Login = function(
aUserID,
aPassword,
__success, __error) {
try {
var msg = this.fMessage.clone();
msg.initialize(this.fServiceName, "Login");
msg.write("aUserID", "Utf8String", aUserID);
msg.write("aPassword", "Utf8String", aPassword);
msg.finalize();
this.fChannel.dispatch(msg, function (__message) {
var __result = __message.read("Result", "Boolean");
var __aUserInfo = __message.read("aUserInfo", "UserInfo");
__success(
__result
,
__aUserInfo
);
}, __error);
} catch (e) {
__error(msg, e);
};
};
// Event sink: DataChangeNotification
__namespace.DataChangeNotification = function DataChangeNotification() {
this.OnDataTableChanged = {
aTableName : {dataType : "Utf8String", value : null},
aDelta : {dataType : "Binary", value : null}
};
};
__namespace.DataChangeNotification.prototype = new RemObjects.SDK.ROEventSink();
__namespace.DataChangeNotification.prototype.constructor = __namespace.DataChangeNotification;
RemObjects.SDK.RTTI["DataChangeNotification"] = __namespace.DataChangeNotification;

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<meta charset="utf-8" />
<title>
Data Abstract dataset demo
</title>
<!-- Bootstrap -->
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<style type="text/css">
body {
padding-top: 60px;
}
</style>
<script src="RemObjectsSDK.js" type="text/javascript"></script>
<script src="DataAbstract.js" type="text/javascript"></script>
<script src="DataAbstract4_intf.js" type="text/javascript"></script>
<script src="sampleda.js" type="text/javascript"></script>
</head>
<body role="document">
<div class="navbar navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<div class="navbar-brand">Data Abstract for Pas2JS</div>
</div>
<button id="btn-fetch" class="btn btn-default">Load Data</button>
<div><a href="sampleda.lpr"> View pascal sources</a></div>
</div>
</div>
<div id="wrapper" class="container" style="display:none;">
<div class="content">
<div class="row">
<table class="table table-bordered table-striped">
<thead>
<th>ID</th>
<th>Name</th>
<th>Phone</th>
</thead>
<tbody id="tableRows"></tbody>
</table>
</div>
</div>
</div>
<hr />
</footer>
<script>
window.addEventListener("load",rtl.run);
</script>
</body>
</html>

View File

@ -0,0 +1,81 @@
<?xml version="1.0" encoding="UTF-8"?>
<CONFIG>
<ProjectOptions>
<Version Value="11"/>
<General>
<Flags>
<MainUnitHasCreateFormStatements Value="False"/>
<MainUnitHasTitleStatement Value="False"/>
<MainUnitHasScaledStatement Value="False"/>
<Runnable Value="False"/>
</Flags>
<SessionStorage Value="InProjectDir"/>
<MainUnit Value="0"/>
<Title Value="sampleda"/>
<UseAppBundle Value="False"/>
<ResourceType Value="res"/>
</General>
<CustomData Count="1">
<Item0 Name="PasJSWebBrowserProject" Value="1"/>
</CustomData>
<BuildModes Count="1">
<Item1 Name="Default" Default="True"/>
</BuildModes>
<PublishOptions>
<Version Value="2"/>
<UseFileFilters Value="True"/>
</PublishOptions>
<RunParams>
<FormatVersion Value="2"/>
<Modes Count="0"/>
</RunParams>
<Units Count="1">
<Unit0>
<Filename Value="sampleda.lpr"/>
<IsPartOfProject Value="True"/>
</Unit0>
</Units>
</ProjectOptions>
<CompilerOptions>
<Version Value="11"/>
<Target FileExt=".js">
<Filename Value="sampleda"/>
</Target>
<SearchPaths>
<IncludeFiles Value="$(ProjOutDir)"/>
<UnitOutputDirectory Value="js"/>
</SearchPaths>
<Parsing>
<SyntaxOptions>
<AllowLabel Value="False"/>
<UseAnsiStrings Value="False"/>
</SyntaxOptions>
</Parsing>
<CodeGeneration>
<TargetOS Value="browser"/>
</CodeGeneration>
<Linking>
<Debugging>
<GenerateDebugInfo Value="False"/>
<UseLineInfoUnit Value="False"/>
</Debugging>
</Linking>
<Other>
<CustomOptions Value="-Jeutf-8 -Jirtl.js -Jc"/>
<CompilerPath Value="$(pas2js)"/>
</Other>
</CompilerOptions>
<Debugging>
<Exceptions Count="3">
<Item1>
<Name Value="EAbort"/>
</Item1>
<Item2>
<Name Value="ECodetoolError"/>
</Item2>
<Item3>
<Name Value="EFOpenError"/>
</Item3>
</Exceptions>
</Debugging>
</CONFIG>

View File

@ -0,0 +1,119 @@
program sampleda;
{$mode objfpc}
uses
JS, Classes, SysUtils, Web, DB, dasdk, dadataset;
Type
{ TSampleForm }
TSampleForm = Class(TComponent)
Private
divWrapper : TJSHTMLElement;
btnGetData : TJSHTMLButtonElement;
tblBody : TJSHTMLElement;
FConn : TDAConnection;
FDataset : TDADataset;
procedure AfterLoad(DataSet: TDataSet; Data: JSValue);
procedure BindElements;
procedure CreateDataset;
procedure DoClientsOpen(DataSet: TDataSet);
function DoGetDataClick(aEvent: TJSMouseEvent): boolean;
procedure DoLoginOK(result: Boolean; UserInfo: TDAUserInfo);
Public
Procedure Show;
end;
{ TSampleForm }
procedure TSampleForm.CreateDataset;
begin
FConn:=TDaConnection.Create(Self);
FConn.URL:='https://sample.remobjects.com/bin';
FConn.OnLogin:=@DoLoginOK;
FConn.StreamerType:=stBin;
FDataset:=TDaDataset.Create(Self);
FDataset.DAConnection:=FConn;
FDataset.TableName:='Clients';
FDataset.AfterOpen:=@DoClientsOpen;
end;
procedure TSampleForm.BindElements;
begin
btnGetData:=TJSHTMLButtonElement(Document.getElementById('btn-fetch'));
btnGetData.onClick:=@DoGetDataClick;
tblBody:=TJSHTMLElement(Document.getElementById('tableRows'));
divWrapper:=TJSHTMLElement(Document.getElementById('wrapper'));
end;
procedure TSampleForm.AfterLoad(DataSet: TDataSet; Data: JSValue);
begin
Writeln('Loaded');
end;
procedure TSampleForm.DoClientsOpen(DataSet: TDataSet);
Function escape(S : String) : String;
begin
Result:=StringReplace(S,'&','&amp;',[rfReplaceAll]);
Result:=StringReplace(S,'<','&lt;',[rfReplaceAll]);
Result:=StringReplace(S,'>','&gt;',[rfReplaceAll]);
Result:=StringReplace(S,'"','&quot;',[rfReplaceAll]);
Result:=StringReplace(S,'''','&#39;',[rfReplaceAll]);
end;
Var
FID,FName,FPhone : TField;
HTML : String;
begin
Writeln('Clients open :',Dataset.RecordCount);
FID:=Dataset.FieldByname('ClientId');
FName:=Dataset.FieldByname('ClientName');
FPhone:=Dataset.FieldByname('ContactPhone');
While not Dataset.EOF do
begin
html:=Html+'<TR><TD>'+Escape(FID.AsString)+'</TD>'
+'<TD>'+Escape(FName.AsString)+'</TD>'
+'<TD>'+Escape(FPhone.AsString)+'</TD></TR>';
Dataset.Next;
end;
tblBody.InnerHTMl:=HTML;
divWrapper['style']:='';
end;
function TSampleForm.DoGetDataClick(aEvent: TJSMouseEvent): boolean;
begin
FConn.LoginEx('User=simple;Password=simple;');
Result:=False;
end;
procedure TSampleForm.DoLoginOK(result: Boolean; UserInfo: TDAUserInfo);
begin
Writeln('Login :',result);
if Result then
begin
divWrapper['style']:='display: none;';
FDataset.Active:=False;
FDataset.Load([],@AfterLoad);
end
else
window.Alert('Failed to log in !')
end;
procedure TSampleForm.Show;
begin
CreateDataset;
BindElements;
end;
begin
With TSampleForm.Create(Nil) do
Show;
end.

View File

@ -0,0 +1,318 @@
{
This file is part of the Free Pascal run time library.
Copyright (c) 2018 by Michael Van Canneyt, member of the
Free Pascal development team
Remobjects Data Abstract external classes.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit DA;
{$mode objfpc}
{$modeswitch externalclass}
interface
uses Types, JS, DASDK;
Type
// Forward classes
TDADataTable = class;
TDABIN2DataStreamer = class;
TDAJSONDataStreamer = class;
TDARemoteDataAdapter = Class;
TDAChange = class;
TDADelta = class;
TDADeltas = class;
TDAField = class;
TDALookupField = class;
TDADataTableRow = class;
TDAExpression = class;
TDADynamicWhere = class;
TDAConstantExpression = class;
TDAParameterExpression = class;
TDANullExpression = class;
TDAFieldExpression = class;
TDAMacroExpression = class;
TDAUnaryExpression = class;
TDABinaryExpression = class;
TDABetweenExpression = class;
TDAListExpression = class;
TDAUtil = Class;
TDARemoteDataAdaptor = Class;
TDAStream = String;
TDADataStreamer = class external name 'RemObjects.DataAbstract.DataStreamer' (TJSObject)
Public
procedure initializeRead;
procedure initializeWrite;
procedure finalizeWrite;
function getStream : TDAStream;
procedure setStream(aStream : TDAStream);
procedure readDataset(aDataset : TDADataTable);
function readDelta : TDADelta;
procedure writeDelta(aDelta : TDADelta);
Property Stream : TDAStream Read getStream write setStream;
end;
TDADataStreamerClass = Class of TDADataStreamer;
TDABIN2DataStreamer = class external name 'RemObjects.DataAbstract.Bin2DataStreamer' (TDADataStreamer)
function readByte : Byte;
function readInteger : NativeInt;
function readAnsiStringWithLength : String;
function readUtf8StringWithLength : string;
function read (aType : string) : TJSObject;
function readParam (acount : Integer) : TDADataParameter;
function readField(acount : Integer) : TDAField;
Procedure writeByte(aValue : Byte);
Procedure writeInteger(aValue : NativeInt);
Procedure writeAnsiStringWithLength(aValue : String);
Procedure write(aType : string; aValue : TJSObject);
end;
TDAJSONDataStreamer = class external name 'RemObjects.DataAbstract.JSONDataStreamer' (TDADataStreamer)
end;
TDARemoteDataAdapter = Class external name 'RemObjects.DataAbstract.RemoteDataAdapter' (TJSObject)
Public
Constructor New(Const aURL, aDataServiceName, aLoginServiceName : String;
aStreamerClass : TDADataStreamerClass);
end;
TDAChange = class external name 'RemObjects.DataAbstract.Change' (TJSObject)
end;
TDAChangeArray = array of TDAChange;
TLogField = record
name : string;
datatype : string;
end;
TLogFieldArray = array of TLogfield;
TDADelta = class external name 'RemObjects.DataAbstract.Delta' (TJSObject)
Private
FData : TDAChangeArray; external name 'data';
FKeyFields : TStringDynArray; external name 'keyfields';
FLoggedFields : TLogFieldArray; external name 'loggedfields';
FName : string; external name 'name';
Public
Function intFindId(anId : Integer) : TDAChange;
Property data : TDAChangeArray Read FData;
Property keyFields : TStringDynArray Read FKeyFields;
Property LoggedFields : TLogFieldArray Read FLoggedFields;
Property Name : String Read FName;
end;
TDADeltas = class external name 'RemObjects.DataAbstract.Deltas' (TJSObject)
Public
Function FindByName (Const aName : String) : TDADelta;
end;
TDATableRowNotifyEvent = reference to procedure(row : TDADataTableRow);
TDADataTableRowArray = array of TDADataTableRow;
TDAFieldArray = Array of TDAField;
TDADataTable = class external name 'RemObjects.DataAbstract.DataTable' (TJSObject)
Public
name : string;
rows : TDADataTableRowArray;
fields : TDAFieldArray;
deletedrows : TDADataTableRowArray;
frecordbuffer : TJSArray;
fNextRecID : Integer;
fIndex : Integer;
bofFlag : Boolean;
eofFlag : Boolean;
dynamicWhere : TJSObject;
onNewRecord : TDATableRowNotifyEvent;
onBeforeDelete: TDATableRowNotifyEvent;
onAfterDelete: TDATableRowNotifyEvent;
onBeforeScroll: TDATableRowNotifyEvent;
onAfterScroll: TDATableRowNotifyEvent;
Procedure checkRequired;
Procedure locate(aName : String; aValue : JSValue);
procedure addLookupField(const aName,aSourceField : String; aLookupTable : TDADataTable;
const aLookupKeyField, aLookupResultField : String);
procedure getNextId;
function appendRow : TDADataTableRow;
procedure deleteRow;
procedure markDeleted;
function fieldNumByName(Const aName : string) : Integer;
function fieldByName(Const aName : string) : TDAField;
procedure setFieldValue(Const aName : string; aValue : JSValue);
function getFieldValue(Const aName : string) : JSValue;
procedure setFieldAsString(Const aName, aValue : String);
function getFieldAsString(Const aName : string) : String;
function currentRow : TDADataTableRow;
procedure first;
procedure last;
procedure next;
procedure prev;
Function findId(anID: Integer) : TDADataTableRow;
function eof : boolean;
function bof : boolean;
procedure post;
procedure cancel;
end;
TDAField = class external name 'RemObjects.DataAbstract.Field' (TJSObject)
Public
alignment : string;
blobtype: string;
businessClassID : String;
calculated : string;
customAttributes : string;
dataType : string;
name: string;
type_ : string external name 'type';
logChanges : boolean;
readOnly : boolean;
serverAutoRefresh : Boolean;
serverCalculated : Boolean;
description : string;
decimalPrecision : Integer;
decimalScale : integer;
defaultValue : string;
dictionaryEntry : String;
displayLabel : String;
displayWidth : integer;
inPrimaryKey : Boolean;
visible : boolean;
required : boolean;
size : integer;
Procedure checkReadOnly;
end;
TDALookupField = class external name 'RemObjects.DataAbstract.LookupField' (TJSObject)
Public
sourceField : string;
lookupTable : TDADataTable;
lookupKeyField: String;
lookupResultField : string;
end;
TDADataTableRow = class external name 'RemObjects.DataAbstract.DataTableRow' (TJSObject)
Public
recID : Integer;
state : string;
__oldValues : array of JSValue;
__newValues : array of JSValue;
end;
TDAExpression = class external name 'RemObjects.DataAbstract.Expression' (TJSObject);
TDADynamicWhere = class external name 'RemObjects.DataAbstract.DynamicWhere' (TJSObject)
Public
constructor New(anExpression : TDAExpression);
function toXML : String;
end;
TDAConstantExpression = class external name 'RemObjects.DataAbstract.ConstantExpression' (TDAExpression)
Public
constructor new (aType : String; aValue : JSValue; ANull : Byte);
end;
TDAParameterExpression = class external name 'RemObjects.DataAbstract.ParameterExpression' (TDAExpression)
Public
constructor new (const aName, aType : String; aSize : Integer);
end;
TDANullExpression = class external name 'RemObjects.DataAbstract.NullExpression' (TDAExpression)
public
constructor new;
end;
TDAFieldExpression = class external name 'RemObjects.DataAbstract.FieldExpression' (TDAExpression)
public
constructor new(aName : string);
end;
TDAMacroExpression = class external name 'RemObjects.DataAbstract.MacroExpression' (TDAExpression)
public
constructor new(aName : string);
end;
TDAUnaryExpression = class external name 'RemObjects.DataAbstract.UnaryExpression' (TDAExpression)
public
constructor new(aNode : TDAExpression; aOperator : string);
end;
TDABinaryExpression = class external name 'RemObjects.DataAbstract.BinaryExpression' (TDAExpression)
public
constructor new(aNode1,aNode2 : TDAExpression; aOperator : string);
end;
TDABetweenExpression = class external name 'RemObjects.DataAbstract.BetweenExpression' (TDAExpression)
public
constructor new(aNode1,aNode2,aNode3 : TDAExpression);
end;
TDAListExpression = class external name 'RemObjects.DataAbstract.ListExpression' (TDAExpression)
public
constructor new(aList : array of TDAExpression);
end;
TDAUtil = Class external name 'RemObjects.DataAbstract.Util' (TJSObject)
Public
function createDataParameter(aName : String;aValue : JSValue) : TJSObject;
function createRequestInfo(IncludeSchema : Boolean; MaxRecords : Integer; UserFilter : String; Parameters : Array of JSValue) : TJSObject;
function createRequestInfoV5(IncludeSchema : Boolean; MaxRecords : Integer; UserFilter : String; Parameters : Array of JSValue) : TJSOBject;
function createRequestInfoV6(SQL : String; MaxRecords : Integer; UserFilter : String; Parameters : Array of JSValue) : TJSObject;
procedure setupScriptingCallBacks;
end;
TDACallBack = procedure;
TDALoginNeededCallBack = reference to procedure(aCallBack : TDACallBack);
TDAChangeFailHandler = reference to procedure (aData : TDAChange);
TDARemoteDataAdaptor = Class external name 'RemObjects.DataAbstract.RemoteDataAdapter' (TJSObject)
Private
FSendReducedDelta : boolean; external name 'sendReducedDelta';
Public
onLoginNeeded : TDALoginNeededCallBack;
onChangeFail : TDAChangeFailHandler;
function getDataService() : TDADataAbstractService;
function getLoginService() : TDASimpleLoginService;
procedure login(aUserID,aPassword,aConnectionName : String; OnSuccess : TDASuccessEvent; OnFailed : TDAFailedEvent);
procedure logout(OnSuccess : TDASuccessEvent; OnFailed : TDAFailedEvent);
function createStreaer: TDAJSONDatastreamer;
procedure setSendReducedDelta (aValue : Boolean);
procedure getSchema(aFilter : String;OnSuccess : TDASuccessEvent; OnFailed : TDAFailedEvent);
function buildDelta(aTable : TDADataTable) : TDADelta;
procedure createTableFromSchema(const aTableName : String; aTable : TDADataTable; CallBack: TDACallBack);
procedure executeCommand(const aName : String; Parameters: TDADataParameterArray; OnSuccess : TDASuccessEvent; OnFailed : TDAFailedEvent);
function getAutoGetScripts : Boolean;
procedure setAutoGetScripts(aValue : boolean);
Procedure getSQLData(aTable : TDADataTable; const SQL : String;OnSuccess : TDASuccessEvent; OnFailed : TDAFailedEvent);
Procedure getData(aTable : TDADataTable; aRequest : TDATableRequestInfo;OnSuccess : TDASuccessEvent; OnFailed : TDAFailedEvent);
procedure applyUpdates(aTable : TDADataTable; OnSuccess : TDASuccessEvent; OnFailed : TDAFailedEvent);
property sendReducedDelta : Boolean Read FSendReducedDelta Write setSendReducedDelta;
property AutoGetScripts : boolean Read getAutoGetScripts write setAutoGetScripts;
end;
TDAHTMLTableView = class external name 'RemObjects.DataAbstract.Views.HtmlTableView'
Public
constructor new(aTable : TDADataTable; aHTMLTableID : String);
end;
TDAVerticalHTMLTableView = class external name 'RemObjects.DataAbstract.Views.VerticalHtmlTableView'
Public
constructor new(aTable : TDADataTable; aHTMLTableID : String);
end;
Implementation
end.

View File

@ -0,0 +1,511 @@
{
This file is part of the Free Pascal run time library.
Copyright (c) 2018 by Michael Van Canneyt, member of the
Free Pascal development team
Dataset which talks to Remobjects Data Abstract server.
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit dadataset;
interface
uses Types, Classes, DB, jsonDataset, JS, rosdk, da, dasdk;
Type
EDADataset = Class(EDatabaseError);
TDAConnection = Class;
{ TDADataset }
TDADataset = class(TBaseJSONDataset)
private
FParams: TParams;
FTableName: String;
FDAConnection: TDAConnection;
FWhereClause: String;
function DataTypeToFieldType(s: String): TFieldType;
procedure SetParams(AValue: TParams);
Protected
Procedure MetaDataToFieldDefs; override;
Public
constructor create(aOwner : TComponent); override;
Destructor Destroy; override;
function DoGetDataProxy: TDataProxy; override;
// DA is index based. So create array field mapper.
function CreateFieldMapper : TJSONFieldMapper; override;
Procedure CreateFieldDefs(a : TJSArray);
Property TableName : String Read FTableName Write FTableName;
Property DAConnection : TDAConnection Read FDAConnection Write FDAConnection;
Property Params : TParams Read FParams Write SetParams;
Property WhereClause : String Read FWhereClause Write FWhereClause;
end;
TDADataRequest = Class(TDataRequest)
Public
Procedure doSuccess(res : JSValue) ;
Procedure DoFail(response : TJSOBject; fail : String) ;
End;
{ TDADataProxy }
TDADataProxy = class(TDataProxy)
private
FConnection: TDAConnection;
function ConvertParams(DADS: TDADataset): TDADataParameterDataArray;
Protected
Function GetDataRequestClass : TDataRequestClass; override;
Public
Function DoGetData(aRequest : TDataRequest) : Boolean; override;
Function ProcessUpdateBatch(aBatch : TRecordUpdateBatch): Boolean; override;
Property Connection : TDAConnection Read FConnection Write FConnection;
end;
TDAMessageType = (mtAuto, // autodetect from URL
mtBin, // use BinMessage
mtJSON); // Use JSONMessage.
TDAStreamerType = (stJSON,stBin);
{ TDAConnection }
TDAConnection = class(TComponent)
private
FDataService: TDADataAbstractService;
FDataserviceName: String;
FLoginService: TDASimpleLoginService;
FLoginServiceName: String;
FMessageType: TDAMessageType;
FMessage : TROmessage;
FChannel : TROHTTPClientChannel;
FOnLoginFailed: TDAFailedEvent;
FOnLogin: TDALoginSuccessEvent;
FStreamerType: TDAStreamerType;
FURL: String;
procedure ClearConnection;
Function GetDataService : TDADataAbstractService;
function GetLoginService: TDASimpleLoginService;
procedure SetDataserviceName(AValue: String);
procedure SetLoginServiceName(AValue: String);
procedure SetMessageType(AValue: TDAMessageType);
procedure SetURL(AValue: String);
Protected
Procedure CreateChannelAndMessage; virtual;
function DetectMessageType(Const aURL: String): TDAMessageType; virtual;
Function CreateDataService : TDADataAbstractService; virtual;
Function CreateLoginService : TDASimpleLoginService; virtual;
Public
Constructor create(aOwner : TComponent); override;
Destructor Destroy; override;
// Returns a non-auto MessageType, but raises exception if it cannot be determined;
Function EnsureMessageType : TDAMessageType;
// Returns DataService, but raises exception if it is nil;
Function EnsureDataservice : TDADataAbstractService;
// Returns SimpleLoginService, but raises exception if it is nil;
Function EnsureLoginservice : TDASimpleLoginService;
// Call this to login. This is an asynchronous call, check the result using OnLoginOK and OnLoginFailed calls.
Procedure Login(aUserName, aPassword : String);
Procedure LoginEx(aLoginString : String);
// You can set this. If you didn't set this, and URL is filled, an instance will be created.
Property DataService : TDADataAbstractService Read GetDataService Write FDataService;
// You can set this. If you didn't set this, and URL is filled, an instance will be created.
Property LoginService : TDASimpleLoginService Read GetLoginService Write FLoginService;
Published
// If set, this is the message type that will be used when auto-creating the service. Setting this while dataservice is Non-Nil will remove the reference
Property MessageType : TDAMessageType Read FMessageType Write SetMessageType;
// if set, URL is used to create a DataService. Setting this while dataservice is Non-Nil will remove the reference
Property URL : String Read FURL Write SetURL;
// DataServiceName is used to create a DataService. Setting this while dataservice is Non-Nil will remove the reference
Property DataserviceName : String Read FDataserviceName Write SetDataserviceName;
// LoginServiceName is used to create a login service. Setting this while loginservice is Non-Nil will remove the reference
Property LoginServiceName : String read FLoginServiceName write SetLoginServiceName;
// Called when login call is executed.
Property OnLogin : TDALoginSuccessEvent Read FOnLogin Write FOnLogin;
// Called when login call failed. When call was executed but user is wrong OnLogin is called !
Property OnLoginCallFailed : TDAFailedEvent Read FOnLoginFailed Write FOnLoginFailed;
// Streamertype : format of the data package in the message.
Property StreamerType : TDAStreamerType Read FStreamerType Write FStreamerType;
end;
implementation
uses strutils, sysutils;
{ TDAConnection }
function TDAConnection.GetDataService: TDADataAbstractService;
begin
if (FDataservice=Nil) then
FDataservice:=CreateDataService;
Result:=FDataService;
end;
function TDAConnection.GetLoginService: TDASimpleLoginService;
begin
if (FLoginService=Nil) then
FLoginService:=CreateLoginService;
Result:=FLoginService;
end;
procedure TDAConnection.SetDataserviceName(AValue: String);
begin
if FDataserviceName=AValue then Exit;
ClearConnection;
FDataserviceName:=AValue;
end;
procedure TDAConnection.SetLoginServiceName(AValue: String);
begin
if FLoginServiceName=AValue then Exit;
FLoginServiceName:=AValue;
end;
procedure TDAConnection.SetMessageType(AValue: TDAMessageType);
begin
if FMessageType=AValue then Exit;
ClearConnection;
FMessageType:=AValue;
end;
procedure TDAConnection.ClearConnection;
begin
FDataservice:=Nil;
FChannel:=Nil;
FMessage:=Nil;
end;
procedure TDAConnection.SetURL(AValue: String);
begin
if FURL=AValue then Exit;
ClearConnection;
FURL:=AValue;
end;
procedure TDAConnection.CreateChannelAndMessage;
begin
if (FChannel=Nil) then
FChannel:=TROHTTPClientChannel.New(URL);
if (FMessage=Nil) then
Case EnsureMessageType of
mtBin : fMessage:=TROBINMessage.New;
mtJSON : fMessage:=TROJSONMessage.New;
end;
end;
function TDAConnection.DetectMessageType(Const aURL : String) : TDAMessageType;
Var
S : String;
begin
S:=aURL;
Delete(S,1,RPos('/',S));
case lowercase(S) of
'bin' : Result:=mtBin;
'json' : Result:=mtJSON;
else
Raise EDADataset.Create(Name+': Could not determine message type from URL: '+aURL);
end;
end;
function TDAConnection.CreateDataService: TDADataAbstractService;
begin
Result:=Nil;
if URL='' then exit;
CreateChannelAndMessage;
Result:=TDADataAbstractService.New(FChannel,FMessage,DataServiceName);
end;
function TDAConnection.CreateLoginService: TDASimpleLoginService;
begin
Result:=Nil;
if URL='' then exit;
CreateChannelAndMessage;
Result:=TDASimpleLoginService.New(FChannel,FMessage,LoginServiceName);
end;
constructor TDAConnection.create(aOwner: TComponent);
begin
inherited create(aOwner);
FDataServiceName:='DataService';
FLoginServiceName:='LoginService';
end;
destructor TDAConnection.Destroy;
begin
ClearConnection;
inherited Destroy;
end;
function TDAConnection.EnsureMessageType: TDAMessageType;
begin
Result:=MessageType;
if Result=mtAuto then
Result:=DetectMessageType(URL);
end;
function TDAConnection.EnsureDataservice: TDADataAbstractService;
begin
Result:=Dataservice;
if (Result=Nil) then
Raise EDADataset.Create('No data service available. ');
end;
function TDAConnection.EnsureLoginservice: TDASimpleLoginService;
begin
Result:=LoginService;
if (Result=Nil) then
Raise EDADataset.Create('No login service available. ');
end;
procedure TDAConnection.Login(aUserName, aPassword: String);
begin
EnsureLoginService.Login(aUserName,aPassword,FOnLogin,FOnLoginFailed);
end;
procedure TDAConnection.LoginEx(aLoginString: String);
begin
EnsureLoginService.LoginEx(aLoginString,FOnLogin,FOnLoginFailed);
end;
{ TDADataset }
function TDADataset.DataTypeToFieldType(s : String) : TFieldType;
Const
FieldStrings : Array [TFieldType] of string = (
'','String', 'Integer', 'LargeInt', 'Boolean', 'Float', 'Date',
'Time', 'DateTime', 'AutoInc', 'Blob', 'Memo', 'FixedChar',
'Variant','Dataset');
begin
if (Copy(S,1,3)='dat') then
system.Delete(S,1,3);
Result:=High(TFieldType);
While (Result>ftUnknown) and Not SameText(FieldStrings[Result],S) do
Result:=Pred(Result);
if Result=ftUnknown then
case LowerCase(s) of
'widestring' : result:=ftString;
'currency' : result:=ftFloat;
end;
end;
procedure TDADataset.SetParams(AValue: TParams);
begin
if FParams=AValue then Exit;
FParams.Assign(AValue);
end;
procedure TDADataset.MetaDataToFieldDefs;
begin
if Not isArray(Metadata['fields']) then
exit;
CreateFieldDefs(TJSArray(Metadata['fields']));
end;
function TDADataset.DoGetDataProxy: TDataProxy;
begin
Result:=TDADataProxy.Create(Self);
TDADataProxy(Result).Connection:=DAConnection;
end;
constructor TDADataset.create(aOwner: TComponent);
begin
inherited;
DataProxy:=nil;
FParams:=TParams.Create(Self);
end;
destructor TDADataset.Destroy;
begin
FreeAndNil(FParams);
Inherited;
end;
procedure TDADataset.CreateFieldDefs(a: TJSArray);
Var
I : Integer;
F : TDAField;
fn,dt : string;
fs : Integer;
FT : TFieldType;
req : boolean;
begin
FieldDefs.Clear;
For I:=0 to A.length-1 do
begin
F:=TDAField(A.Elements[i]);
fn:=F.Name;
fs:=F.Size;
dt:=F.type_;
req:=F.Required;
Ft:=DataTypeToFieldType(dT);
if (ft=ftBlob) and (fs=0) then
fs:=1;
FieldDefs.Add(fn,ft,fs,Req);
end;
end;
function TDADataset.CreateFieldMapper: TJSONFieldMapper;
begin
Result := TJSONArrayFieldMapper.Create;
end;
{ TDADataProxy }
function TDADataProxy.ConvertParams(DADS : TDADataset) : TDADataParameterDataArray;
Var
I : integer;
begin
Result:=Nil;
Writeln('Converting ',DADS.Params.Count,' parameters.');
if DADS.Params.Count=0 then
Exit;
SetLength(Result,DADS.Params.Count);
for I:=0 to DADS.Params.Count-1 do
begin
Result[i].Name:=DADS.Params[i].Name;
Result[i].Value:=DADS.Params[i].Value;
end;
end;
function TDADataProxy.DoGetData(aRequest: TDataRequest): Boolean;
Var
TN : TDAStringArray;
TIA : TDATableRequestInfoArray;
TID : TDATableRequestInfoV5Data;
TI : TDATableRequestInfoV5;
Srt : TDAColumnSortingData;
R : TDADataRequest;
DADS : TDADataset;
PA : TDADataParameterDataArray;
DS : TDADataAbstractService;
begin
// DA does not support this option...
if loAtEOF in aRequest.LoadOptions then
exit(False);
DADS:=aRequest.Dataset as TDADataset;
R:=aRequest as TDADatarequest;
if (Connection=Nil) then
Raise EDADataset.Create(Name+': Cannot get data without connection');
DS:=Connection.EnsureDataservice;
TN:=TDAStringArray.New;
TN.fromObject([DADS.TableName]);
TID.maxRecords:=-1;
TID.IncludeSchema:=True;
Srt.FieldName:='';
Srt.SortDirection:='Ascending';
TID.Sorting:=Srt;
TID.UserFilter:='';
if DADS.WhereClause<>'' then
TID.WhereClause:=DADS.WhereClause;
PA:=ConvertParams(DADS);
if Length(PA)>0 then
TID.Parameters:=Pa;
TIA:=TDATableRequestInfoArray.new;
// We need to manually fill the array
TI:=TDATableRequestInfoV5.New;
TI.FromObject(TID);
TJSArray(TIA.items).push(TI);
DS.GetData(TN,TIA,@R.doSuccess,@R.doFail);
Result:=True;
end;
function TDADataProxy.GetDataRequestClass: TDataRequestClass;
begin
Result:=TDADataRequest;
end;
function TDADataProxy.ProcessUpdateBatch(aBatch: TRecordUpdateBatch): Boolean;
begin
Result:=False;
end;
{ TDADataRequest }
procedure TDADataRequest.DoFail(response: TJSOBject; fail: String);
Var
O : TJSOBject;
S : TStringDynArray;
Msg : String;
I : Integer;
begin
if isObject(fail) then
begin
O:=TJSOBject(JSValue(fail));
S:=TJSObject.getOwnPropertyNames(O);
for I:=0 to Length(S)-1 do
begin
msg:=Msg+sLineBreak+S[i];
Msg:=Msg+' : '+String(O[S[i]]);
end;
end
else
Msg:=Fail;
writeln('Data request or processing failed: ',Msg);
Success:=rrFail;
end;
procedure TDADataRequest.doSuccess(res: JSValue);
Var
S : String;
Rows : TJSArray;
DADS : TDADataset;
DStr : TDADataStreamer;
DT : TDADatatable;
I : Integer;
begin
// Writeln('Data loaded, dataset active: ',Dataset.Active);
DADS:=Dataset as TDADataset;
if not Assigned(DADS.DAConnection) then
Raise EDADataset.Create(DADS.Name+': Cannot process response, connection not available');
S:=String(Res);
if (DADS.DAConnection.EnsureMessageType=mtJSON) then
S:=TROUtil.Frombase64(S);
Case DADS.DAConnection.StreamerType of
stJSON : DStr:=TDABIN2DataStreamer.new;
stBIN: DStr:=TDABIN2DataStreamer.new;
end;
DStr.Stream:=S;
DStr.initializeRead;
DT:=TDADataTable.New;
DStr.ReadDataset(DT);
Rows:=TJSArray.New;
for I:=0 to length(DT.rows)-1 do
Rows.Push(DT.Rows[i].__newValues);
(Dataset as TDADataset).Metadata:=New(['fields',TJSArray(DT.Fields)]);
// Data:=aJSON['data'];
(Dataset as TDADataset).Rows:=Rows;
Success:=rrOK;
DoAfterRequest;
end;
end.

View File

@ -0,0 +1,217 @@
{
This file is part of the Free Pascal run time library.
Copyright (c) 2018 by Michael Van Canneyt, member of the
Free Pascal development team
Remobjects Data Abstract external classes definitions
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit dasdk;
{$mode objfpc}
{$modeswitch externalclass}
interface
uses JS, ROSDK;
Type
TDAUserInfo = Class;
TDASuccessEvent = Procedure (res : JSValue) of object;
TDAFailedEvent = Procedure (response : TJSOBject; fail : String) of object;
TDALoginSuccessEvent = Reference to Procedure (result : Boolean; UserInfo : TDAUserInfo);
TDABaseLoginService = class external name 'RemObjects.DataAbstract.Server.SimpleLoginService' (TJSObject)
Public
Constructor new(ch : TROHTTPClientChannel; msg : TROMessage; aServiceName : string);
Procedure LoginEx(aLoginString :String; aSuccess : TDALoginSuccessEvent; aFailure : TDAFailedEvent);
Procedure Logout(aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
end;
TDASimpleLoginService = class external name 'RemObjects.DataAbstract.Server.SimpleLoginService' (TDABaseLoginService)
Public
Procedure Login(aUserId,aPassword :String; aSuccess : TDALoginSuccessEvent; aFailure : TDAFailedEvent);
end;
TDAStringArray = class external name 'RemObjects.DataAbstract.Server.StringArray'
Public
constructor new;
procedure fromObject(aItems : array of string); overload;
end;
TDADataParameterData = Record
Name: string;
Value : JSValue;
End;
TDADataParameterDataArray = array of TDADataParameterData;
TDADataParameter = class external name 'RemObjects.DataAbstract.Server.DataParameter' (TROStructType)
Public
constructor new;
Procedure fromObject(aItem : TDADataParameterData); overload;
Public
Name : TROValue;
Value : TROValue;
end;
TDADataParameterArray = class external name 'RemObjects.DataAbstract.Server.DataParameterArray' (TROArrayType)
Public
constructor new;
Procedure fromObject(aItems : Array of TDADataParameterData); overload;
function toObject : TDADataParameterDataArray; reintroduce;
Public
items : Array of TDADataParameter;
end;
TDAColumnSortingData = record
FieldName : String;
SortDirection : String;
end;
TDAColumnSortingDataArray = Array of TDAColumnSortingData;
TDAColumnSorting = class external name 'RemObjects.DataAbstract.Server.ColumnSorting' (TROStructType)
Public
FieldName : TROValue;
Direction : TROValue;
end;
TDAColumnSortingArray = class external name 'RemObjects.DataAbstract.Server.ColumnSortingArray' (TROArrayType)
Public
constructor new;
Procedure fromObject(aItems : Array of TDAColumnSortingData); overload;
function toObject : TDAColumnSortingDataArray; reintroduce;
Public
items : Array of TDAColumnSorting;
end;
TDATableRequestInfoData = record
IncludeSchema : boolean;
MaxRecords : Integer;
Parameters : TDADataParameterDataArray;
UserFilter : String;
end;
TDATableRequestInfoDataArray = array of TDATableRequestInfoData;
TDATableRequestInfo = class external name 'RemObjects.DataAbstract.Server.TableRequestInfo' (TROStructType)
Public
constructor new;
procedure fromObject(aItem : TDATableRequestInfoData);reintroduce; overload;
procedure fromObject(aItem : TJSObject);reintroduce; overload;
Function toObject : TDATableRequestInfoData; reintroduce;
Public
IncludeSchema : TROValue;
MaxRecords : TROValue;
Parameters : TROValue;
UserFilter : TROValue;
end;
TDATableRequestInfoV5Data = record
DynamicSelectFieldNames : Array of string;
IncludeSchema : boolean;
MaxRecords : Integer;
Parameters : Array of TDADataParameterData;
UserFilter : String;
Sorting : TDAColumnSortingData;
WhereClause : String;
end;
TDATableRequestInfoV5 = class external name 'RemObjects.DataAbstract.Server.TableRequestInfoV5' (TROStructType)
Public
constructor new;
procedure fromObject(aItem : TDATableRequestInfoV5Data);reintroduce;overload;
procedure fromObject(aItem : TJSObject);reintroduce;overload;
function toObject : TDATableRequestInfoV5Data;reintroduce;
Public
DynamicSelectFieldNames : TROValue;
IncludeSchema : TROValue;
MaxRecords : TROValue;
Parameters : TROValue;
UserFilter : TROValue;
Sorting : TROValue;
WhereClause : TROValue;
end;
TDATableRequestInfoV6Data = record
IncludeSchema : boolean;
MaxRecords : Integer;
Parameters : Array of TDADataParameterData;
SQL : String;
UserFilter : String;
end;
TDATableRequestInfoV6 = class external name 'RemObjects.DataAbstract.Server.TableRequestInfoV6' (TROStructType)
Public
constructor new;
procedure fromObject(aItem : TDATableRequestInfoData);reintroduce;overload;
procedure fromObject(aItem : TJSObject);reintroduce;overload;
function toObject : TDATableRequestInfoV6Data;reintroduce;
Public
IncludeSchema : TROValue;
MaxRecords : TROValue;
Parameters : TDADataParameterArray;
Sql : TROValue;
UserFilter : TROValue;
end;
TDAUserInfoData = record
Attributes : array of JSValue;
Privileges : Array of string;
SessionID : String;
UserData : JSValue;
UserID : String;
end;
TDAUserInfo = class external name 'RemObjects.DataAbstract.Server.UserInfo' (TROStructType)
constructor new;
procedure fromObject(aItem : TDAUserInfo);reintroduce; overload;
procedure fromObject(aItem : TJSObject);reintroduce; overload;
function toObject : TDAUserInfoData;reintroduce;
Public
Attributes : TROValue;
Privileges : TROValue;
SessionID : TROValue;
UserData : TROValue;
UserID : TROValue;
end;
TDATableRequestInfoArray = class external name 'RemObjects.DataAbstract.Server.TableRequestInfoArray' (TROArrayType)
Public
constructor new;
procedure fromObject(aItems : Array of TDATableRequestInfoData);overload;
procedure fromObject(aItems : Array of TDATableRequestInfoV5Data);overload;
procedure fromObject(aItems : Array of TDATableRequestInfoV6Data);overload;
procedure fromObject(aItems : array of TJSObject);overload;
Public
items : array of TDATableRequestInfo;
end;
TDADataAbstractService = class external name 'RemObjects.DataAbstract.Server.DataAbstractService'
Public
Constructor new(ch : TROHTTPClientChannel; msg : TROMessage; aServiceName : string);
Procedure GetSchema(aFilter : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure GetData(aTables : TDAStringArray; info : TDATableRequestInfoArray; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure UpdateData(aDelta : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure ExecuteCommand(aCommandName : String; params : TDADataParameterArray; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure ExecuteCommandEx(aCommandName : String; params : TDADataParameterArray; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure GetTableSchema(aTableNameArray : TDAStringArray;aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure GetCommandSchema(aCommandNameArray : TDAStringArray;aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure GetSQLData(aSQLText : String; aIncludeSchema : Boolean; aMaxRecords : Integer; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure GetSQLDataEx(aSQLText : String; aIncludeSchema : Boolean; aMaxRecords : Integer; aDynamicWhereXML : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure SQLExecuteCommand(aSQLText : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure SQLExecuteCommandEx(aSQLText,aDynamicWhereXML : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure getDatasetScripts(DatasetNames : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure RegisterForDataChangeNotification(aTableName : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
Procedure UnregisterForDataChangeNotification(aTableName : String; aSuccess : TDASuccessEvent; aFailure : TDAFailedEvent);
end;
implementation
end.

View File

@ -0,0 +1,211 @@
{
This file is part of the Free Pascal run time library.
Copyright (c) 2018 by Michael Van Canneyt, member of the
Free Pascal development team
Remobjects SDK external classes definitions
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit ROSDK;
{$mode objfpc}
{$modeswitch externalclass}
interface
uses
Types, JS;
Type
TROValue = record
dataType : string;
value : JSValue;
end;
TROComplexType = class;
TROEnumType = class;
TROStructType = class;
TROArrayType = class;
TROException = class;
TROEventSink = class;
TROClientChannel = class;
TROHTTPClientChannel = class;
TROMessage = class;
TROJSONMessage = class;
TROBinMessage = class;
TROBinHeader = class;
TRORemoteService = class;
TROService = class;
TROEventReceiver = class;
TROUtil = class external name 'RemObjects.UTIL' (TJSObject)
Public
class function toBase64 (Const aValue : String) : String;
class function fromBase64 (Const aValue : String) : String;
class procedure showMessage (Const msg : string);
class procedure showError(Const msg : string; e : JSValue);
class function toJSON(aValue : jsValue) : String;
class function parseJSON (Const aValue : string) : JSValue;
class function NewGuid() : string;
class function GuidToArray(Const aGuid : string) : TIntegerDynArray;
class function guidToByteArray(Const aGuid : string): String;
class function zeroPad(const num : string; count : integer) : String;
class function byteArrayToGuid(const byteArray : string) : String;
class function strToByteArray (const str : string) : string;
class function byteArrayToStr(const byteArray : string) : string;
class function byteArrayToUtf16(const byteArray : string) : string;
class function utf16ToByteArray(const str : string) : string;
class function ISO8601toDateTime(const str: String) : TJSDate;
class function dateTimeToSOAPString(aValue: TJSDate) : string;
class function decimalToString(aDecimal : array of integer ) : string;
class function stringToDecimal(const aString : String) : TIntegerDynArray;
class Function checkArgumentTypes (args : Array of JSValue; types : array of string) : Boolean;
end;
TROException = class external name 'RemObjects.SDK.ROException' (TJSError);
TROComplexType = class external name 'RemObjects.SDK.ROComplexType' (TJSObject)
Public
Procedure readFrom(aMessage : TROMessage);
Procedure writeTo(aMessage : TROMessage);
end;
TROEnumType = class external name 'RemObjects.SDK.ROEnumType' (TROComplexType)
Public
Procedure fromObject(aObject : TJSObject); overload;
Function toObject(aStoreType : Boolean) : TJSObject;overload;
end;
TROStructType = class external name 'RemObjects.SDK.ROStructType' (TROComplexType)
Public
Procedure fromObject(aObject : TJSObject);overload;
Function toObject(aStoreType : Boolean) : TJSObject;overload;
end;
TROArrayType = class external name 'RemObjects.SDK.ROArrayType' (TROComplexType)
Public
Procedure fromObject(aObject : Array of TJSObject);overload;
Function toObject(aStoreType : Boolean) : TJSObjectDynArray;overload;
end;
TRODispatchSuccessEvent = reference to Procedure (msg : TROMessage);
TRODispatchFailedEvent = reference to Procedure (msg : TROMessage; aError : TJSError);
TROCallBack = Procedure;
TROOnLoginNeeded = reference to procedure(aCallBack : TROCallBack);
TROClientChannel = class external name 'RemObjects.SDK.ClientChannel' (TJSObject)
Public
onLoginNeeded : TROOnLoginNeeded;
Public
Constructor new(aURL : String);
Procedure dispatch(aMessage : TROMessage; onSuccess : TRODispatchSuccessEvent; OnError : TRODispatchFailedEvent);
end;
TROHTTPCallback = reference to procedure (aResponse : String; aStatus : Integer);
TROHTTPClientChannel = class external name 'RemObjects.SDK.HTTPClientChannel' (TROClientChannel)
Public
Procedure post(aMessage : TROMessage; isBinary : Boolean; OnSuccess,OnError : TROHTTPCallback);
end;
TROEventSink = class external name 'RemObjects.SDK.ROEventSink' (TJSObject)
Public
Procedure readEvent(aMessage : TROMessage; aName : string);
end;
TROMessage = class external name 'RemObjects.SDK.Message' (TJSObject)
Public
constructor new;
Function Clone : TROMessage;
function getClientID : String;
procedure setClientID(const aValue : String);
function getErrorMessage : String;
procedure setErrorResponse (Const aResponse : String);
Procedure initialize (Const aServiceName,aMethodName : string; aMessageType : Integer);
Procedure finalize;
function requestStream : String; // Dummy
procedure setResponseStream(const aValue : String);
function read (const aName,aType : String) : TROValue;
Procedure write (const aName,aType : String; aValue : JSValue);
Property ClientID : String Read getClientID Write setClientID;
end;
TROJSONMessage = class external name 'RemObjects.SDK.JSONMessage' (TROMessage)
end;
TROBinHeader = class external name 'RemObjects.SDK.BinHeader' (TJSObject)
Public
function asStream: String;
Procedure ReadFrom(aStream : String);
function isValidHeader : Boolean;
function getCompressed : Boolean;
Procedure setCompressed(aValue : Boolean);
function getMessageType : integer;
Procedure setMessageType(aValue : integer);
procedure setClientID(aValue : String);
Property Compressed : Boolean Read getCompressed Write setCompressed;
Property MessageType : Integer Read getMessageType write SetMessageType;
end;
TROBinMessage = class external name 'RemObjects.SDK.BinMessage' (TROMessage)
public
constructor new;
Procedure writeVariant(aValue : JSValue);
Procedure writeinteger(aValue : Integer);
Procedure writeStrWithLength(aValue : string);
function readByte : Byte;
function readCompressed : String;
function readVariant : JSValue;
end;
TROEventCallback = reference to procedure (event : TJSObject); // Or TROComplexType ?
TROEventReceiver = class external name 'RemObjects.SDK.ROEventReceiver' (TJSObject)
Public
Constructor new(aChannel : TROClientChannel; aMessage : TROMessage; aServiceName : string; aTimeOut : Integer);
Procedure addHandler(anEventName : String; aCallback : TROEventCallback);
Procedure setActive(aValue : boolean);
function getActive : Boolean;
function getTimeout : integer;
procedure setTimeout(aValue : Integer);
Procedure intPollServer;
Property Active : Boolean Read GetActive Write SetActive;
Property TimeOut : Integer read GetTimeOut Write SetTimeout;
end;
TRORemoteService = Class external name 'RemObjects.SDK.RemoteService' (TJSObject)
Constructor new(aChannel : TROClientChannel; aMessage : TROMessage; aServiceName : string);
end;
TROService = Class external name 'RemObjects.SDK.ROService' (TJSObject)
Public
Constructor new(aService : TRORemoteService);
Constructor new(aChannel : TROClientChannel; aMessage : TROMessage; aServiceName : string);
function getMessage : TROMessage;
function getChannel : TROClientChannel;
function getServiceName : String;
Property Message : TROMessage Read getMessage;
Property Channel : TROClientChannel Read getChannel;
Property ServiceName : String Read getServiceName;
end;
TROBinaryParser = Class external name 'BinaryParser' (TJSObject)
procedure warn;
function decodeFloat(data : JSValue; precisionbits,exponentbits :Integer) : double;
function encodeFloat(value: double; precisionbits,exponentbits :Integer) : string;
function decodeInt(data : JSValue; bits : Integer; Signed : boolean) : NativeInt;
function encodeInt(data : NativeInt; bits : Integer; Signed : boolean) : String;
end;
implementation
end.