SCAN [examples]

Scans over records in a table and executes a command block for each selected record

use customers
seek "HMT"
scan rest while code = "HMT"
    echo "name=" + name + "address=" + address
endscan

https://www.lianja.com/doc/index.php/SCAN


 

Advertisements

RSP [examples]

Return the value of a parameter passed to a .rsp script or return an alternative value if the parameter was not passed

// WebView URL Attribute
quickreport.rsp?database=southwind&table=example&fields=*&heading=Client List (all)&columns=2,4,3,5,6,7,8,9,10,11,12&subtotals=9,10,11&gridlines=true
 
//--
// quickreport.rsp?parameter=value&parameter=value...
//
// parameters 
//--
private database   = getParameter("database", "southwind") 
private table      = getParameter("table", "example") 
private fields     = getParameter("fields", "*") 
private groupby    = getParameter("groupby", "") 
private heading    = getParameter("heading", "Report for all clients by state") 
private headings   = getParameter("headings", "") 
private filter     = getParameter("filter", "") 
private hyperlink  = getParameter("hyperlink", "") 
private columns    = getParameter("columns", "") 
private subtotals  = getParameter("subtotals", "") 
private gridlines  = getParameter("gridlines", "")
// ...

https://www.lianja.com/doc/index.php/GETPARAMETER()


Execute an rsp script

execRSP("test.rsp?customerid=alfki")

test.rsp

<%@ Language=VFP %>
<%
    local m_customerID = getParameter("customerID", "")
    local m_tempfile = tmpnam()
    if database() <> "southwind"
        open database southwind
    endif
    set strcompare on  // perform autotrim and case insensitive string comparisons in queries 
    select * from customers where customerid=m_customerid into cursor temp
    select temp
    copy to &m_tempfile type csv
    type &m_tempfile
    erase &m_tempfile
%>

https://www.lianja.com/doc/index.php/EXECRSP()


Return the value of a session variable in a .rsp script or return an alternative value if the variable does not exist

ss=len(_SESSION)
if ss > 0
	? "Active session variables ("+alltrim(str(ss))+")"
	foreach _session as name=>value 
		? "<br>   &name="+etos(value)
		next
else
	? "There are no active session variables."
endif
 
?"<br>"
? "start_time = " + getsessionvar("start_time",time())
?"<br>"

https://www.lianja.com/doc/index.php/GETSESSIONVAR()


 

example_cookies.rsp

This Visual FoxPro Server Page (.rsp) demonstrates querying of the _SERVER[], _SESSION[] and _COOKIE global associative arrays.

<%@ Language=VFP %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lianja example - accessing cookies</title>
</head>
<body>
<%
  // Get the hostname for the remote machine requesting the page
  ? "_server[ ] elements"
  foreach _server as name=>value 
    ? "<br>   &name="+etos(value)
  next
  ? "<br><br>"
  ? date()
  ? time()
  ? "<br><br>"
 
  cc=len(_COOKIE)
  if cc > 0
	? "Active session Cookies ("+alltrim(str(cc))+")"
	foreach _cookie as name=>value 
		? "<br>   &name="+etos(value)
	endfor
  else
	? "There are no active session cookies."
  endif
  ? "<br><br>"
 
  ss=len(_SESSION)
  if ss > 0
	? "Active session variables ("+alltrim(str(ss))+")"
	foreach _session as name=>value 
		? "<br>   &name="+etos(value)
	next
  else
	? "There are no active session variables."
  endif
 
  ? "<br><br>Press the browser refresh key."
  _session["time"] = time()
%>
</body>
</html>

https://www.lianja.com/doc/index.php/Cookies_rsp

https://www.lianja.com/doc/index.php/Example_cookies_rsp


 

example_authentication.rsp

This Visual FoxPro Server Page (.rsp) demonstrates how to use the response object authenticate() method for user authentication.

<%@ Language=VFP %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lianja example - authentication</title>
</head>
<body>
<%
  if len(_SERVER["AUTH_TYPE"]) = 0 .or. len(_SERVER["REMOTE_USER"]) = 0 .or. len(_SERVER["REMOTE_PASSWORD"]) = 0
	response.Authenticate()
  endif
  ? "Hi " + proper(_SERVER["REMOTE_USER"]) + ", You have authenticated successfully."
  ? '<br>'
%>
</body>
</html>

https://www.lianja.com/doc/index.php/Authentication_rsp

https://www.lianja.com/doc/index.php/Example_authentication_rsp


 

example_imagequery.rsp

This Visual FoxPro Server Page (.rsp) demonstrates the use of the base64_encode_file() function to generate the base64 encoded contents of an object field image as an IMG tag and output it into the HTML5.

<%@ Language=VFP %>
<html>
<head>
</head>
<body>
<%
  ? "<table width='80%' align=center cellpadding=12>"
  ? "<tr>"
  ? "<td align=center colspan=2>"
  ? "<h1>Lianja example - image queries</h1>"
  ? '<p>Customize this to suit your own needs. This is a just an example.<p>'
  ? '<hr size="1px" color="lightgray"/>'
  ? "</td>"
  ? "</tr>"
  ? "<tr>"
  ? "<td colspan=2>"
  ? "<h3>Employees</h3>"
  ? "</td>"
  ? "</tr>"
 
  // scan through the employees table
  open database southwind
  use employees
  scan
	? "<tr>"
	? "<td>"
	m_tmpnam = tmpnam()
	objectwrite(m_tmpnam,photo)
	base64_encode_file(m_tmpnam, objectType(photo), "200px", "200px")
	erase &m_tmpnam
	? "</td>"
	? "<td>"
	? mtos(notes) + "<a href='../odata/southwind/orders("+etos(employeeid)+",employeeid)'> JSON download of orders for ";
          + trim(firstname) + " " + lastname + "</a>"
	? "</td>"
	? "<tr>"
	? '<td colspan="2">'
	? '<hr size="1px" color="lightgray"/>'
	? "</td>"
	? "</tr>"
	? "</tr>"
  endscan
  close data
 
  ? "<tr>"
  ? "<td align=center colspan=2>"
  ? "<p>Copyright © 2013 Lianja Inc. All rights reserved worldwide.</p>"
  ? "<h3><a href 'http://www.lianja.com'> www.lianja.com</a></h3>"
  ? "</td>"
  ? "</tr>"
  ? "</table>"
%>
</body>
</html>

https://www.lianja.com/doc/index.php/Example_imagequery_rsp

https://www.lianja.com/doc/index.php/Imagequery_rsp


 

example_datanavigation.rsp

Example Visual FoxPro Server Page (.rsp) demonstrating basic data navigation.

<%@ Language=VFP %>
<html>
<body>
<%
    // Open the database
    open database southwind
    ? "<br>"
 
    // Open the table
    use customers
 
%>
<table>
<tr>
<%
     // Display the table headings
    for i = 1 to fcount()
        ? "<td>" + field(i) + "</td>"
    next
%>
</tr>
<%
    // Display the data in a table
    scan
        ? "<tr valign='top'>"
        for i = 1 to fcount()
            ? "<td>"
            ? &(field(i))
            ? "</td>"	
        next
        ? "</tr>"
    endscan
    // close the table and the database
    use
    close database
%>
</table>
</body>
</html>

https://www.lianja.com/doc/index.php/Example_rsp

https://www.lianja.com/doc/index.php/Example_datanavigation_rsp


 

example_redirection.rsp

This Visual FoxPro Server Page (.rsp) demonstrates the use of the response object redirect() method for URL redirection.

<%@ Language=VFP %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Lianja example - redirection</title>
</head>
<body>
<%
	response.redirect("/default.rsp")
%>
</body>

https://www.lianja.com/doc/index.php/Example_redirection_rsp


 

pfooter.rsp

This Visual FoxPro Server Page (.rsp) is a Page Footer gadget example. See Page Footers for more information.

<%@ Language=VFP %>
<html>
<head>
<style>
table, td, th {
    border: 1px solid black;
}
table {
    border-collapse: collapse;
    width: 100%;
}
td {
    text-align: center;
}
</style>
</head>
<body>
<%
	private m_count = 0
	private m_total = 0
	private m_min = 0
	private m_max = 0
	private m_ordertotal = 0
	private m_linetotal = 0
 
	save recordview
 
	if used("orders") and used("customers")
		select orders
		seek customers.customerid
		scan while customerid = customers.customerid
			++m_count
			select order_details
			seek orders.orderid
			m_ordertotal = 0
			m_linetotal = 0
			scan while orderid = orders.orderid
				m_linetotal = (order_details.unitprice*order_details.quantity) - order_details.discount
				m_ordertotal = m_ordertotal + m_linetotal
			endscan
			if m_min = 0 or m_min > m_ordertotal
				m_min = m_ordertotal
			endif
			if m_max = 0 or m_max < m_ordertotal
				m_max = m_ordertotal
			endif
			m_total = m_total + m_ordertotal
		endscan
	endif
 
	m_min = currency(m_min)
	m_max = currency(m_max)
	m_total = currency(m_total)
 
	restore recordview
 
	text raw 
	<table>
	<tr>
	<th>
    <font color=darkgray>Total Orders</font>
	</th>
	<th>
	<font color=darkgray>Min Order Value</font>
	</th>
	<th>
	<font color=darkgray>Max Order Value</font>
	</th>
	<th>
	<font color=darkgray>Total Order Value</font>
	</th>
	</tr>
	<tr>
	<td>
	<font color=gray>&m_count</font>
	</td>
	<td>
    <font color=gray>&m_min</font>
	</td>
	<td>
    <font color=gray>&m_max</font>
	</td>
	<td>
    <font color=gray>&m_total</font>
	</td>
	</tr>
	</table>
	</body>
	endtext
%>
</body>
</html>

https://www.lianja.com/doc/index.php/Pfooter.rsp


 

Categories RSP

Report section [examples]

Quick Report on a hyperlink of the field.

reports_script_deleg

The Hyperlink value will be passed as an argument to a script. In the example below, when the orderid Hyperlink is clicked, a new PDF report is created in the background to list the order details and then displayed.

////////////////////////////////////////////////////////////////
// Event delegate for 'linkclicked' event
proc page1_section1_linkclicked(arg)
	// Generate and display a PDF report on the order details
	// using a hidden WebView Section and the Library report.rsp
	myreport = createObject("
	myreport.url = "lib:/report.rsp?database=southwind&table=order_details";
	    +"&fields=*&filter=orderid="+etos(arg);
	    +"&heading=Order Details for Order "+etos(arg)
	myreport.refresh()
	cTempfile = sys(3) + ".pdf"
	myreport.print('', 'Portrait', 'PDF', cTempfile)
	showdocument("file:///"+cTempfile)
endproc

https://www.lianja.com/doc/index.php/Developing_Quick_Reports


The Reports in the ‘Lianja Demo’ (lianjademo) App use quickreport.rsp in this way, e.g. the Report overdue payments report:

URL:quickreport.rsp?database=southwind&table=example&fields=*&groupby=state
    &filter=available<0&heading=Customer Credit List (over limit)
    &columns=2,4,3,5,6,7,8,9,10,11,12&subtotals=9,10,11&gridlines=true

https://www.lianja.com/doc/index.php/Report_Options


 

 

 

 

 

 

Recordview [examples]

Save the status of the currently active workarea to a memory variable 

procedure check_value
  save recordview to m_recv
  // Validate data
  restore recordview from m_recv
return

https://www.lianja.com/doc/index.php/SAVE_RECORDVIEW


Restore a previously saved workarea status 
procedure check_value
  save recordview to m_recv
  // Validate data
  restore recordview from m_recv
return

 


 

Query Picker [examples]

 

function myQueryPickerCallback(key, value)
{
    messageBox("You chose '"+value+"'");
}
 
var title = "Browse Orders";
var onselect = "myQueryPickerCallback()";
var database = "southwind";
var table = "order_details";
var params = "";    // e.g. parameter=value&parameter2=value...
var width = 900;
Lianja.showQueryPickerPanel(title, onselect, database, table, params, width);
////////////////////////////////////////////////////////////////////////////////
function myButtonClick(btntext, value)
{
    messageBox("You clicked the '"+btntext+"' button for '"+value+"'");
}

https://www.lianja.com/doc/index.php/QueryPicker

 

Query Builder [examples]

 

var sectionid = "page1.section1";    // or "myCallBackHandler()"
var database = "southwind";
var table = "order_details";
var columns = "";   
var filter = "";
Lianja.showQueryBuilderPanel(sectionid, database, table, columns, filter);

var sectionid = "page1.section1";    // or "myCallBackHandler()"
var database = "southwind";
var table = "order_details";
var columns = "";   
var filter = "";
var modal = false;
var minbuttons = false;
Lianja.showQueryBuilder(sectionid, database, table, columns, filter, modal, minbuttons);

https://www.lianja.com/doc/index.php/QueryBuilder


 

Python [examples]

Run Python code

// Character field
create table if not exists scripts (script char(200))
if not used("scripts")
	use scripts
endif
select scripts
append blank
replace script with 'for i in range(9):' + CHR(13)+ '# process commands' + CHR(13)
execpython(script)
 
// Text constant
execpython('for i in range(9):' + CHR(13) + '# process commands' + CHR(13))
 
// Memory variable
m_script = 'for i in range(9):' + CHR(13) + '# process commands' + CHR(13)
execpython(m_script)

https://www.lianja.com/doc/index.php/EXECPYTHON()


Python:

To open a Lianja database from Python

import Lianja
db = Lianja.openDatabase("southwind")

https://www.lianja.com/doc/index.php/Working_with_data_in_Python


Python:

After we have opened a recordset we can navigate through the data using any of the recordset data navigation methods of the Recordset class.

Access a table in the database using the openRecordSet() method of the Database class using SQL or noSQL. For example we can access the customers table using SQL like this:

rs = db.openRecordSet("select * from customers")

Or alternatively just open the customers table with noSQL like this:

rs = db.openRecordSet("customers")

Recordset data navigation

For example to position on the first record in a recordset use the moveFirst() method.

rs.moveFirst()

Extract data from the Recordset

When you are positioned on a particular record in a recordset you can extract data using the fields() method.

for i in range(rs.fields.count):
   name = rs.fields(i).name
   value = rs.fields(i).value

The fields() method can also take the field name as an argument as well as the column ordinal position.

value = rs.fields("amount").value

Filtering selected data

When you open a recordset with an SQL select statement, the data selected is only that which matches the where condition of the select statement. If you open a table with noSQL e.g.

rs = db.openRecordSet("customers")

noSQL keyed data access

When opening a table in noSQL mode, you can lookup records by keys.

rs = db.openRecordSet("customers")
rs.index = "id"
rs.seek("12345")
if rs.nomatch():
   # key was not found.

Adding new records

You can add new blank records to a recordset using the addNew() method.

rs.addNew()

Note that after executing addNew() the record is not written until the update() method is called. This allows you to update the fields of the blank record prior to it being committed into the table.

Updating records

You can update records in a recordset using the update() method.

rs = db.openRecordSet("customers")
rs.index = "id"
rs.seek("12345")
if !rs.nomatch():
   rs.fields("amount").value = rs.fields("amount").value + 1000
   rs.update()

Deleting records

You can delete records in a recordset using the delete() method.

rs = db.openRecordSet("customers")
rs.index = "id"
rs.seek("12345")
if !rs.noMatch():
   rs.delete()

Closing a Recordset

You close a recordset using the close() method.

rs.close()

https://www.lianja.com/doc/index.php/Working_with_data_in_Python