Transfer Array into SQLite and vice versa without looping especially in ActionScript3 - sqlite

I am very new to programming in ActionScript3 and using SQLite. Currently I try to make an AIR application where it will handle from small to large dataset from excel, import into and calculate in AIR using ActionScript3 and stored the calculated data in SQLite.
Right now I have 2 question regarding using array to transfer data into SQLite
1. Is it possible to INSERT data or UPDATE data in SQLite without using looping?
In my AIR application, I have an object called DataInput in which have 62 variables/properties which will contain 62 different values from 62 columns in excel. I do know that if you create new instance of DataInput and push into array e.g arDataInput in loop, you can access each of the data in the array using arDataInput[i].variablename where i is the index of the array and variablename is the variables/properties of the object.
Obviously, right now I do actually using for loop to access the value of each cell in excel then calculate in AIR application before transfer the calculated data into SQLite, row by row within sql transaction.
Is there actually a way to transfer data in array into SQLite (either INSERT new row or UPDATE existing row) without using loop like INSERT INTO tblDataInputUW VALUES arDataInput given that each column name in SQLite table is the same as variables/properties of object within the array eg. SQLite table, tblDataInput have column name namePlat and array have variables/properties of arDataInput.namePlat?
2. Is it possible to split the data array i got from SQLite into multiple array without looping?
Right now, I use the following code to extract data from SQLite and stored as an array;
txtSQL = new String();
arData = new Array();
txtSQL = "SELECT namePlat, platLat, platLong FROM tblDataInput";
arData = getSQLData(txtSQL);
function getSQLData(text: String): Array
{
sqlCon.begin();
sqlStat = new SQLStatement();
sqlStat.sqlConnection = sqlCon;
sqlStat.text = text;
sqlStat.execute();
sqlCon.commit();
var result: SQLResult = new SQLResult();
var arData: Array = new Array();
result = sqlStat.getResult();
if (result != null)
{
arData = result.data;
}
return arData;
}
If my assumption are correct, I can access each of the value in arData by using arData[i].variablename where i is the index of the array and variablename is the table name within the SQLite table tblDataInput.
If there are way to split the data in arData into 3 different array e.g arNamePlat without using looping like arNamePlat = arData.variablename because I have many different chart to draw in my AIR application and each chart will have its own array to get value from.
Right now, I actually using different sql statement for different chart like;
txtSQL = new String();
arData = new Array();
txtSQL = "SELECT namePlat FROM tblDataInput";
arData = getSQLData(txtSQL);
dgNamePlat.dataProvider = new DataProvider(arData);
txtSQL = new String();
arData = new Array();
txtSQL = "SELECT platLat, platLong FROM tblDataInput";
arData = getSQLData(txtSQL);
dgPlatLatLong.dataProvider = new DataProvider(arData);
I use the same arData and txtSQL for each chart as I dont store the value anymore after the chart been drawn.
There are actually no restriction for me to just use for loop, I asking this question as I don't see any topic regarding on this question and as a self-learning programmer, I like to explore different way of coding and way to incorporate that knowledge into my projects.

The best way to send and receive data and do database stuff is through form submissions. AIR can POST regular form submissions like html pages but can also load a response. Regular serverside software like php handles the form submission, does whatever with the database, and returns data or simple success message.
The best way to handle data is to use XML (look into RESTful architecture for reasons why). PHP creates XML for the app. The xml gets loaded and should go into arrays of objects.
Here are some good links to get going on submitting data with forms and reading XML:
republic of code tutorials:
http://www.republicofcode.com/tutorials/flash/as3contactform/2.php
http://www.republicofcode.com/tutorials/flash/as3xml/
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequest.html
https://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/net/URLRequestMethod.html

Related

What do I need to learn for accessing data from mssql database?

I am learning asp.net core mvc and API. I can simply work on it for CRUD operation. But, I get confused for accessing data from multiple tables like listing all categories with showing number of items each categories contains. What I need to learn for example Lina, entity framework code first, ado.net? I am currently using entity framework code first.
Thanks
Learn Dapper a simple object mapper for .NET.
What I Understood from your problem is that you have multiple tables and you want to query them and map the query result in your c# or vb code.Here I will show simple mapping of query result to c# objects.
Suppose you have three tables category_1,category_2 and category_3.
Lets say each table have two columns named itemName and ItemValue.
Lets create c# class corresponding to each table.
class category_1{
string ItemName {get;set};
int ItemValue {get;set;};
}
class category_2{
string ItemName {get;set};
int ItemValue {get;set;};
}
class category_3{
string ItemName {get;set};
int ItemValue {get;set;};
}
Suppose your querying three tables and map the result of query to respective object in c#.
let our sql query be as follows:
string sql = #"select * from category_1;select * from category_2;select * from category_3;"
Here we have three select statements and each select statement will give you result of respective table.Lets query the above sql to database using dapper and map them to c# object as follows.
List<category_1> lstCotegory1 = new List<category_1>();
List<category_2> lstCotegory2 = new List<category_2>();
List<category_3> lstCotegory3 = new List<category_3>();
using (var multi = connection.QueryMultiple(sql))
{
lstCotegory1 = multi.Read<category_1>().ToList(); // map first select statement
lstCotegory2 = multi.Read<category_2>().ToList(); // map second select statement
lstCotegory3 = multi.Read<category_3>().ToList(); // map third select statement.
}
This is how you can return results of multiple queries and map them to appropriate object. I know you can do better than this but to understand we have to go with simple example.Hope this will help.

Query through SPListCollection

I wonder if it's somehow possible to query a SPListCollection object using SPQuery, as with SPListItemCollection. Imagine that you want to find out which lists were created by a given Author or visible for a given user, for example.
No, this is not possible with SPQuery! But i would prefer you using KeywordQuery:
using (SPSite siteCollection = new SPSite("http://server/sitecollection"))
{
KeywordQuery keywordQuery = new KeywordQuery(siteCollection);
keywordQuery.QueryText = "SharePoint";
SearchExecutor searchExecutor = new SearchExecutor();
ResultTableCollection resultTableCollection = searchExecutor.ExecuteQuery(keywordQuery);
var resultTables = resultTableCollection.Filter("TableType", KnownTableTypes.RelevantResults);
var resultTable = resultTables.FirstOrDefault();
DataTable dataTable = resultTable.Table;
}
Within the Keywordquery you could use for example contentclass STSList to retrieve only lists. And in this case when only using contentclass:"STSList" then you would get all lists where the executor has permissions. You can narrow down by adding additional query parameters. SharePoint search is what you are looking for.

Use SQL IN inside vb.net dataset adaptor

I'm trying to use a dataset adapter in my asp.net/vb.net website. But I need to search using multiple values, Ideally, i'd just like to pass an in statement in to my dataset adapter. Is this possible, as how it is, it doesn't seem to bring back anything:
Heres my data adapter:
The query is:
select * from joblist where username in (#username)
I'm trying to call it with:
Private dtJobs As Barry.joblistDataTable
Private taJobs As New BarryTableAdapters.joblistTableAdapter
dtJobs = New Barry.joblistDataTable
dtJobs = taJobs.FilterSearch("'tomb','martinm','chrise'")
rptJobList.DataSource = dtJobs
rptJobList.DataBind()
What am I doing wrong?
You're passing in a comma separated string, a single parameter. You cannot use it as is in an IN statement.
You have to split it into table, for example using this solution. Using this function (I assume you're using SQL Server as your DB) you can rewrite your query as:
select joblist.* from joblist
inner join dbo.Split(',', #username) t
on joblist.username = t.s
This approach splits your multi-value parameter into table and joins to the original table

Retrieving a list of Tridion 2009 components with a specific value and schema without using search

I would like to create a .NET page residing on the CMS server that shows all components that are based on a specific Schema(tcm:3-3-8) and from a specific Publication(tcm:0-3-1) including BluePrinted and Localized items, but only if they have the value "http://www.google.com" for the field "URL" in that Schema.
Is this possible, without using the search service as this is rather slow and unreliable?
Your search might be slow because of not indexing the search collection.
You should do indexing the search collection on regular intervals for better and fast results.
That's an expensive operation to do because of the cost of opening each individual component to check the value of a field, but certainly do-able.
Get the schema object
Get a list of components that use this schema (WhereUsed on the schema with filter on ItemType = component)
Open each component and check the value for the field(s), add to a List<Component> if it matches
Display list (possibly using a ASP.NET GridView)
I have not had any chance to test it, but something like this
Common common = new Common();
TDSE tdse = new TDSE();
ListRowFilter ComponentFilter = tdse.CreateListRowFilter();
Schema schema = (Schema)common.getObject("tcm:126-238630-8", ItemType.ItemTypeSchema);
ComponentFilter.SetCondition("ItemType", ItemType.ItemTypeComponent);
ComponentFilter.SetCondition("Recursive", true);
XDocument doc = common.ReadXML(schema.Info.GetListUsingItems(ListColumnFilter.XMLListID, ComponentFilter));
List<Component> MatchedComponents = new List<Component>();
XmlNamespaceManager NS = new XmlNamespaceManager(new NameTable());
NS.AddNamespace("tcm", "http://www.tridion.com/ContentManager/5.0");
NS.AddNamespace("Content", "uuid:4432F3C3-9F3E-45E4-AE31-408C5C46E2BF");
foreach (XElement component in doc.XPathSelectElements("/tcm:ListUsingItems/tcm:Item", NS))
{
Component comp = common.getComponent(component.Attribute("ID").Value);
XDocument compDoc = common.ReadXML(comp.GetXML(XMLReadFilter.XMLReadData));
foreach (XElement compNode in compDoc.XPathSelectElements("/tcm:Component/tcm:Data/tcm:Content/Content:Content/Content:feederUrl", NS))
{
MatchedComponents.Add(comp);
}
}

Process data from service in flex

I have created a PHP service in Flex Mobile and binded the result with a List. I want to sort the records from the service based on some calculation on data fields. So, is it possible to perform operations on the resultset from the PHP service ?
Detailed question:
I have created the php service through the built in tool in Flash Builder 4.6. I also had bind the service with a List in my view. (Again using GUI controls). Now I want to rearrange the items in the list based on distance from the current location and coordinates from the rows returned by the service. So the approach I was thinking was to, get the content from the service. Extract lat,lon and calculate the distance. Then update the list again.
I tried the following line in a function:
getAllplacesResult.lastResult[1].lon // lon is a column in the table.
But it returns a blank. Is their a more sane or easier way to do this ?
The better way is to assign it on an Arraycollection and manipulate data from there.
<mx:ArrayCollection id="myAC" source="{ArrayUtil.toArray(myRO.getAllplacesResult.lastResult)}" />
Make sure you bind myAC to your List.
Sort it the way you want to:
var collection:ArrayCollection = new ArrayCollection();
var s:Sort = new Sort();
s.fields = [new SortField("lat"), new SortField("lon")];
s.compareFunction = myCompareFunction;
collection.sort = s;
collection.refresh();
private function myCompareFunction(a:Object, b:Object, fields:Array = null):int {
...
}
Also, AS3 is 0 based index. 1 will actually give you the second row (or throw out of range exception)

Resources