PDA

View Full Version : Lianja Server Pages quick start



barrymavin
2015-07-17, 18:39
When building Web and Mobile Apps in Lianja, WebViews can be dynamically generated using dynamic server pages.

For those who don't already know, the V8 JavaScript engine is embedded into Lianja Cloud Server.

Let's just quickly review Lianja Cloud Server.

The Lianja Cloud Server includes the following features/functionality:

-- An embedded version of the Lianja database engine
-- Lianja SQL Server for ODBC data access
-- Lianja OData Server
-- Lianja WebSockets Server
-- Lianja/VFP Server Pages (.rsp files)
-- Lianja/JavaScript Server Pages (.jssp files)
-- Handles interaction with Lianja HTML5/JavaScript Web Apps
-- Handles interaction with Lianja HTML5/JavaScript PhoneGap Mobile Apps

Dynamic server pages contain HTML5 and directives that tell the Cloud Server how to process the contents of the page.

<%@ Language=VFP %>
or
<%@ Language=JavaScript %>

Let's see some example code.




<%@ Language=JavaScript %>
<!--
Lianja/VFP Server pages (.rsp) have the complete Lianja scripting engine embedded in them.
---------------------------------------------------------------------------------------------
When a Lianja/VFP Server Page is executed the following are available to the script
in addition to the complete VFP compatible cross-platform scripting language
implemented in Lianja.

Global associative arrays:

_REQUEST[]
_SERVER[]
_ARGS[]
_GET[]
_POST[]
_FILES[]
_COOKIE[]
_SESSION[]

Global objects:

Response
write( text )
writeFile( filename )
addCookie(name, value)
addHeader(name, value)
clear()
flush()
redirect( url )
authenticate( [message] )
appendToLog( message )
include( filename )

Built-in commands/functions:

? cExpression
echo cExpression
move_uploaded_file(tofilename, fromfilename)
die(message)
include( cExpression )
object = require( cExpression )
odata_Create( url, jsondatastring )
odata_Read( url [, filename] )
odata_Update( url, jsondatastring )
odata_Delete( url, jsondatastring )

JavaScript Server Pages are modelled on PHP Server Pages.
---------------------------------------------------------
When a JavaScript Server Page is executed the following are available to the script
in addition to the built-in JavaScript functions. These will be familiar to PHP
Web developers.

Global associative arrays(objects):

$_REQUEST[]
$_SERVER[]
$_ARGS[]
$_GET[]
$_POST[]
$_FILES[]
$_COOKIE[]
$_SESSION[]

Global objects:

Lianja.
execute( vfp_command )
evaluate( vfp_expression )
openDatabase( databasename )
openRecordSet( table_or_sqlselect )
moveFirst()
moveNext()
movePrevious()
moveLast()
move()
moveRelative()
moveBookmark()
findFirst( condition )
findNext( condition )
findPrevious( condition )
findLast( condition )
edit()
update()
delete()
requery()
field( name_or_number )
.name
.type
.width
.decimals
.value
close()
bof
eof
found
nomatch
recno
reccount
fieldcount
index
filter
close()
Response
write( text )
writeFile( filename )
addCookie(name, value)
addHeader(name, value)
clear()
flush()
redirect( url )
authenticate( [message] )
appendToLog( message )
include( filename )

Built-in functions:

print( cExpression );
echo( cExpression );
move_uploaded_file(tofilename, fromfilename);
die(message);
debugout(message);
include( cExpression );
object = require( cExpression );
odata_Create( url, jsondatastring );
odata_Read( url [, filename] );
odata_Update( url, jsondatastring );
odata_Delete( url, jsondatastring );
tmpnam()
objectType( object_fieldname )
objectRead( from_filename, object_fieldname )
objectWrite( to_filename, object_fieldname )
base64_encode_object( object_fieldname, width, height)
unlink( filename )


The following is an example Lianja JavaScript Server Page.

-->
<html>
<body>
<%
// Note that just as in PHP, JavaScript Server Pages can use include_once( filename) and include(filename)
// The path of the filename is relative to the directory containing this script.
include_once("library_example.jssp");


// The Lianja global object provides embedded database access
db = Lianja.openDatabase("southwind");
print("db=" + typeof db);
print("<br>");

// Lianja.openDatabase() returns a Database object so now we can open a RecordSet
rs = db.openRecordSet("select * from customers");
print("rs=" + typeof rs);
print("<br>");
print("Fieldcount="+rs.fieldcount);
print("<br>");
%>
<table>
<%
print("<tr>");
for (i=0; i<rs.fieldcount; ++i)
{
print("<td>"+rs.field(i).name+"</td>");
}
print("</tr>");
rs.moveFirst();
for (j=0; j<rs.reccount; ++j)
{
print("<tr valign='top'>");
for (i=0; i<rs.fieldcount; ++i)
{
print("<td>"+rs.field(i).value+"</td>");
}
print("</tr>");
rs.moveNext();
}
rs.close();
db.close();
%>
</table>
</body>
</html>


PS. There are many examples in the examples directory. Run them like this.

http://localhost/examples/example_request.rsp

Reading these examples will show you how to upload files, handle authentication and much more.

Question:

Do you need to write code like this to run Lianja Web and Mobile Apps.

Answer:

If you follow best practices no you don't but if you want to format a custom WebView section or use a third party JavaScript framework this is when you would use dynamic server pages.

And by the way, they are *very* fast. HTTP web connections and ODBC connections to MSSQL / MySQL / PostgreSQL etc are pooled internally.

hmischel@diligentsystems.com
2015-07-17, 18:57
My comment about the RSP pages being fast....

I would say they are very, very fast!;)

Seriously - if you haven't tried using them, try them.

Herb

phabio
2015-07-20, 02:02
thanks Barry.

Fabio