Can Flash be integrated with SQL? - sql

Can Flash be used together with SQL? I have a Flash form and I need to connect it to SQL. If there is any example on the net about this topic. I can't find it.

You don't use ActionScript directly with an SQL database. Instead you make http requests from ActionScript to a server, specifying the correct parameters. A typical opensource setup, is a PHP script communicating with a MySQL DB, but you can use Java with Oracle, Ruby with CouchDB, .NET with SQL or any other possible configuration. The important point is that you must be able to call a server script and pass variables... typically a Restful setup.
Once your PHP script has been properly configured, you can use http POST or http GET to send values from ActionScript.
PHP:
<?php
$updateValue = $_POST["updateValue"];
$dbResult = updateDB( $updateValue ); //This should return the db response
echo( $dbResult );
?>
To call this script from ActionScript, you need to create a variables object.
var variables:URLVariables = new URLVariables();
variables.updateValue = "someResult";
The variable name .updateValue, must match the php variable exactly.
now create a URLRequest Object, specifying the location of your script. For this example the method must be set to POST. You add the variable above to the data setter of the request.
var request:URLRequest = new URLRequest( "yourScript.php" );
request.method = URLRequestMethod.POST;
request.data = variables;
Now create a URLLoader and add an event listener. Do not pass the request created above to the constructor, but to the load method.
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, onComplete );
loader.load( request );
The handler would look something like this.
private function onComplete( e:Event ) : void
{
trace( URLLoader( e.target ).data.toString() );
}
This example shows how to update and receive a response from a server / db combo. However, you can also query a DB through the script and parse the result. So in the PHP example above, you can output JSON, XML or even a piped string, and this can be consumed by ActionScript.
XML is a popular choice, as ActionScript's e4x support treats XML like a native object.
To treat the response above like an XML response, use the following in the onComplete handler.
private function onComplete( e:Event ) : void
{
var result:XML = XML( URLLoader( e.target ).data );
}
This will throw an error if your xml is poorly formed, so ensure the server script always prints out valid XML, even if there is a DB error.

The problem with this is giving someone a flash file that directly accesses SQL server is very insecure. Even if it's possible, which I have seen SOCKET classes out there to do so for MySQL (though never used it), allowing users to remotely connect to your DB is insecure as the user can sniff the login information.
In my opinion, the best way to do this is to create a Client/Server script. You can easily do this with PHP or ASP.net by using SendAndLoad to send the data you need to pass to SQL via POST fields. You can then send back the values in PHP with:
echo 'success='.+urlencode(data);
With this, flash can access the data via the success field.
I don't personally code flash but I work with a company who develops KIOSK applications for dozens of tradeshow companies, and my job is to store the data, return it to them. This is the method we use. You can make it even cleaner by using actual web services such as SOAP, but this method gets the job done if its just you using it.

You should look into Zend Amf or even the Zend Framework for server side communication with Flash. As far as I know Zend Amf is the fastest way to communicate with PHP ( therefore your database ) also you can pass & return complex Objects from the client to the server and vice versa.
Consider this , for instance. You have a bunch of data in your database , you implement functions in ZF whereas this data is formatted and set as a group of Value Objects. From Flash , you query ZF , Zf queries the database , retrieve & formats your data, return your Value Objects as a JSON string ( for instance ). In Flash, you retrieve you JSON string , decode it and assign your Value Objects to whatever relevant classes you have.
There are plenty of tutorials out there regarding Flash communication with the Zend Framework.
Here's an example:
http://gotoandlearn.com/play.php?id=90

Related

Adding an encryption layer to DataTables.js

I’m currently using DataTables.js with server-site data source written on PHP.
The server-side script gives out the data exactly as required by datatables:
{“iTotalDisplayRecords”:”777”,”sEcho”:0,”aaData”:[[row1],[row2],[row3]]}
Now I would like to add an additional security layer with encrypting the response from the server and decrypting it after it is received by datatables.
I need this as I noticed some of the clients work through HTTPS proxy and the content of some rows get mistakenly blocked.
I’m using this solution for server-side PHP script to give out encrypted content using openssl_encrypt.
Then at client side I have:
function datatable_init (source) {
$.getJSON(source, function(data) {
decryptedContent = JSON.parse(CryptoJSAesDecrypt(“password”, data));
oTable = $(‘dtable’).dataTable({
“bProccesing”: false,
“bServerSide: true,
//“sAjaxSource”: source,
“data”: decryptedContent
...
});
I had to replace ”sAjaxSource” to ”data” as it is different datasource type now which requires different type of datatable JSON format:
{data:[[row1],[row2],[row3]}
and I can’t to pass iTotalDisplayRecords anymore.
Is there a way I can keep feeding server-side format of JSON to datatable but feed it as a local JS object/array?
P.S. Another idea I had is to encrypt/decrypt each individual row of the table but that’s probably going to be more complicated and slower
The ajax.dataSrc option seems to be helpful, because it provides the possibility to modify the data received via ajax and thus allows you to define a function which takes care of decrypting the received data again. Especially the last example given on the reference page looks promising in my opinion.

How can I force NEST to NOT populate request on Bulk API response?

I've been looking all over the place and haven't been able to find a suitable answer to this question. I've created a NEST client using this code:
var myIndex = "myTestIndex";
var myType = "myTestType";
var myClusterUri= "http://localhost:9200";
var uri = new Uri(myClusterUri);
var settings = new ConnectionSettings(uri);
var client = new ElasticClient(settings);
and then later, using this to make a call to the bulk api.
var myJson = PopulateJsonForBulkAPI();
var rawBulkResult = client.Raw.Bulk(myIndex, myType, myJson);
The problem I'm having is that I'm getting an OutOfMemoryException when making the bulk api call. The method that populates myJson creates a HUGE block of JSON but not big enough to throw the exception (but big enough to throw it, if it were duplicated). Then when I make the call to the bulk api it throws the OutOfMemoryException because NEST holds onto the original request (in essence, duplicating the JSON and not having enough memory to hold onto everything). Is there a way to make the call to the Bulk API but tell NEST to NOT hold onto the original request so the huge block of JSON isn't duplicated in memory?
Edit
I'm using NEST version 1.7.2 and ElasticSearch version 1.7.2
In NEST 1.x, the request bytes are always made available on the response but you could write a HttpConnection implementation that doesn't do this, overriding DoSynchronousRequest and DoAsyncRequest.
If you're getting OutOfMemoryExceptions though, this sounds like you're trying to send too much data in one bulk request. Consider splitting up the data into batches of bulk requests.

after receiving soap response modify xml and send to anther service using http adapter

while using http adapter I need to call first service that return XML,
after receiving the response I want to change values and send back to anther service,
how can I do it ?
do http adapter has json to xml function ?
WL adapter will automatically convert XML to JSON for you, however it doesn't have any manual JSON<->XML conversion APIs.
In your case possible solution might be to retrieve XML as plaintext by supplying returnedContentType:"plain" in invocation options. Alter whatever you need using regex/string replace. Use resulting string in 2nd procedure invocation as post body.
Alternatively, you can use 3rd party library to parse/convert/do whatever you need with XML, e.g. http://www.json.org/java/ (more info about how to use it in your adapter - http://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v506/04_08_Using_Java_in_adapters.pdf)
After checking number of solutions, I state the the http result will be a plain text,
then made a call to java function sending the xml as String, and used
javax.xml to hold and alter the XML.
XPath to retrieve the correct node using org.w3c.dom.*
Hope this will help you too.

How to add new row to a sharepoint list in objective c?

I tried using updatelistitems web service of the sharepoint. but could not find how to give the input data in the xml format along with the soap request.
Thanks in advance
Since it's an integration you are doing I'd recommend using an ADO.NET adapter for SharePoint and connect through a WCF service (soap/wsdl). It will save you a lot of time and if done correctly your integration wont be proprietary.
Check this ready-made wcf service, http://www.bendsoft.com/downloads/camelot-wcf-service/, installation instructions here http://blog.bendsoft.com/category/integrations/wcf-services/.
It's open source but ships with support for the Camelot XML format, which bundles the schema along with the content if you query for data, check the example schema here http://www.bendsoft.com/downloads/sharepoint-web-parts/xml-pusher/.
To insert data into SharePoint with the WCF service you can simply do something like this
$SharePointNonQuery = new SharePointNonQuery(array(
'sql' => "INSERT INTO contactform (title,email,company,message) VALUES ('John Doe','john.doe#example.com','Johns Company','A test message!')",
'method' => 'ExecuteNonQuery',
'connString' => 'sharepoint_connection',
'sharedKey' => constant("WSDL_SHARED_KEY")
));
The example is obviously made in PHP ( http://blog.bendsoft.com/2011/04/camelot-php-tools-1-1-for-sharepoint-released/ ) but it's equally easy to create a class in Objective-C and send your command as SQL via SOAP and execute the SQL command in the WCF service.
Hope this helps!
----------- Edits below this line -----------
Querying the suggested WCF service from Objective-C would result in something like this
WSMethodInvocationRef soapReq = createSOAPRequest(url, method, namespace, params, paramOrder, reqHeaders);
The Url is the location of the wcf service, ie. http://yourserver.com/wcf/camelot.wcf
The method is the method IN the wcf service you want to use. The Camelot WCF service have a few default methods. Suitable in this scenario would be the ExecuteNonQuery method which takes the following arguments; sql, connString and sharedKey.
bool ExecuteNonQuery(string sql, string connString, string sharedKey);
The params is the arguments listed above, they should be sent as an associative array (NSDictionary I assume).
NSDictionary *params = [NSDictionary dictionaryWithObjectsAndKeys:
#"INSERT INTO YourList (title,email,company,message) VALUES ('John Doe','john.doe#example.com','Johns Company','A test message!')", #"sql",
#"connString", #"SharePointConnectionString",
#"sharedKey", #"YourPreferredKey",
nil];
The ExecuteNonQuery is a bool method it will return true or false to the soapReq method in the Objective-C application.

VEMap and a GeoRSS feed(hosted separately)

The scenario is as follows:
A WCF web service exists that outputs a valid GeoRSS feed. This lives in its own domain as a number of different applications have access to it.
A web page(on a different site) has been created with an instance of a VEMap(Bing/Virtual Earth map object).
Now, VEMap can accept an input feed in this format via the following:
var layer = new VEShapeLayer();
var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "someurl", layer);
map.ImportShapeLayerData(veLayerSpec, onComplete, true);
onComplete is a callback function I'm using to replace the default pin graphic with something custom.
The question is in regards to "someurl", which is a path to a local xml file containing the geographic information(georss simple format). I've realized this feed and the map must be hosted in the same domain, so I've created a generic handler that reads the remote feed and returns it in the same format.
var veLayerSpec = new VEShapeSourceSpecification(VEDataType.GeoRSS, "/somelocalhandler.ashx", layer);
When I do this, I get the VEMap error("z is null"). This is the same error one would receive when trying to access a remote feed. When I copy the feed into a local xml file(ie, "feed.xml") there is no error.
The order of operations is currently: remote feed -> local handler -> VEMap import
If I'm over complicating this procedure, let me know! I'm a bit new to the Bing Maps API and might have missed something. Any assistance is appreciated.
The format I have above is actually very close to what I needed. A similar solution was found by Mike McDougall. Although I was passing the RSS feed directly through the handler(writing the read stream directly), I just needed to specify the following from within the handler:
context.Response.ContentType = "text/xml";
context.Response.ContentEncoding = System.Text.Encoding.UTF8;
With the above fix, I'm able to have a remote GeoRSS feed successfully load a separately hosted Virtual Earth map instance.