Select query of sqlite in metro app? - wpf

I have seen quite a number of examples describing the usage of SQLite in Metro app. Most of the examples have either Orderby/Insert/Delete statements. May I know how do I get the data from a pre-populated db using the Select statement?
Secondly, how does someone store the data into an array or arrayList after the execution of the query?
Kindly help me with this,
Thanks.

See if this example is what you're looking for:
return db.runAsync('SELECT * FROM Table');
Here is a pretty useful article on it.
Extending the example to C#:
SQLiteAsyncConnection conn = new SQLiteAsyncConnection("people");
var query = conn.Table<Person>().Select();
var result = await query.ToListAsync();

Related

Google Apps Script: Use array out of spreadsheet

I try to use Google Script Apps (instead of VBA which I am more used to) and managed now to create a loop over different spreadsheets (and not only different sheets in one document) using the forEach function.
(I tried with a for (r=1;r=lastRow; r++) but I did not manage).
It is working now defining the array for the sheetnames manually:
var SheetList = ["17DCu1nyyX4a6zCkkT3RfBSfo-ghoc2fXEX8chlVMv5k", "1rRGQHs_JShPSBIGFCdG6AqXM967JFhdlfQ92cf5ISL8", "1pFDyXgYmvC5gnN5AU5xJ8vGiihwtubcbG2n4LPhPACQ", "1mK_X4Q7ysJQTt8NZoZASBE5zuUllPmmWSJsxu5Dnu9Y", "1FpjIGWTG5_6MMYJF72wvoiBRp_Xlt5BDpzvSZKcsU"]
And then for information the loop:
SheetList.forEach(function(r) {
var thisSpreadsheet = SpreadsheetApp.openById(r)
var thisData = thisSpreadsheet.getSheetByName('Actions').getDataRange()
var values = thisData.getValues();
var toWorksheet = targetSpreadsheetID.getSheetByName(targetWorksheetName);
var last = toWorksheet.getLastRow ()+ 1
var toRange = toWorksheet.getRange(last, 1, thisData.getNumRows(), thisData.getNumColumns())
toRange.setValues(values);
})
Now I want to create the definition of the array "automatically" out of the spreadsheet 'List' where all spreadsheets which I want to loop are listed in column C.
I tried several ideas, but always failed.
Most optimistic ones were:
var SheetList = targetSpreadsheetID.getSheetByName('List').getRange(2,3,lastRow-2,3).getValues()
And I also tried with the array-function:
var sheetList=Array.apply(targetSpreadsheetID.getSheetByName('List').getRange(2,3,lastRow-2,3))
but all without success.
It should be possible normally in more or less one single line to import the array from the speadsheet to the Google apps scripts?
I would very much appreciate if someone could please give me a hint where my mistake is.
Thank you very much.
Maria
I still did not manage to put the array as I wanted it initially, but now I found a workable solution with the For Loop which I want to share here in case someone is looking for a similar solution (and then finds at least my workaround ;) )
for (i=2; i<lastRow;i++){
var SheetList = targetSpreadsheetID.getSheetByName('List').getRange(i,3).getValues()
Logger.log(SheetList);
var thisSpreadsheet = SpreadsheetApp.openById(SheetList);
... // the rest identical to loop above...
Don't hesitate to add your comments or advice anyhow, but I will mark the question as closed.
Thanks a lot.
Maria

Quickbooks Online Api - Is there a way to get a list of all available custom fields for Invoice?

I have been going through the Intuit Developer documentation for about 10 hours trying to find a way to get a list of invoice "custom fields" that have been set up for a Quickbooks Online Company file. I'm not sure if it is even possible. It if is, can anyone point me to some code, documentation, or anything that could possibly help me get such a list. Is it available somehow through the QueryService? Any assistance is greatly appreciated!
This gets custom fields:
public static List<Preferences> getCustomFields()
{
ServiceContext serviceContext = getServiceContext();
QueryService<Preferences> preferencesQueryService = new QueryService<Preferences>(serviceContext);
return preferencesQueryService.ExecuteIdsQuery("Select * FROM Preferences").ToList<Preferences>();
}
List<Preferences> prefs = RestHelper.getCustomFields();
List<CustomFieldDefinition> cusfieldDefs = prefs[0].SalesFormsPrefs.CustomField.ToList() as List<CustomFieldDefinition>;
List<StringTypeCustomFieldDefinition> customFields = cusfieldDefs.OfType<StringTypeCustomFieldDefinition>().ToList();
I started here: API Reference.
As well, to grab all of the fields with values I made a query to the Quickbooks record, with a SELECT * statement. That brings everything back, with data.

Displaying Parse Data to ContainerList

I want to display data from Parse in a list from GamesScores class using Container in Codename One, this is what I've tried so far and it's not showing anything nor giving any errors:
Container container = findListCont();
container.setLayout(BoxLayout.y());
container.setScrollableY(true);
ParseQuery<ParseObject> query = ParseQuery.getQuery("GameScore");
List<ParseObject> results = (List<ParseObject>) query.find();
System.out.println("Size: " + results.size());
container.addComponent(results, f);
Please help me out, I'm a new in Codename One. If there tutorials on it, please share or anything to help me achieve the desired results.
I'm actually shocked this isn't failing. You are using the add constraint to place the object result as a constraint and you add the form object into the container...
You need to loop over the results and convert them to components to add into the layout. It also seems that you are using the old GUI builder which I would recommend against.
Generally something like this rough pseudo code should work assuming you are using a box Y layout:
for(ParseObject o : results) {
MultiButton mb = new MultiButton(o.getDisplayValue());
f.add(mb);
}
f.revalidate();

XPcollection not loaded - why?

This must be something very simple, I just don't see it (and can not find the answer :(
I am trying to learn DevExpress controls and have read that eXpress Persistent Objects is recommended for O/R mapping.
1) I have an existing SQL Server Compact 4.0 database for which I generated ORM
2) I have a Winform with XtraGrid.GridControl gridControl1
3) In Form_Load event I have this code:
XPCollection cName = new XPCollection(typeof(WindowsFormsApplication1.DUzskv1r6.XPO_TableName));
int c = cName.Count; //didn't help...
cName.DisplayableProperties = "Name;Nr"; //choose columns to display
gridControl1.MainView.PopulateColumns();
gridControl1.DataSource = cName;
I have read that it using "delayed loading" - loading when it is necessary (http://documentation.devexpress.com/#XPO/clsDevExpressXpoXPCollectiontopic), but reading XPcollections record Count didn't do the trick as it was suggested.
As a result I get an empty gridControl1 with columns "Name" and "Nr".
Please help - what am I missing?
I think the issue is somewhere in your datalayer initialization.
You use XPCollection with default session, maybe you forgot to initialize it.
The best way is to specify the session is in the XPCollection contractor.

Saving and updating (SQL Server rows) using SubSonic 3.0 and LINQ

I feel foolish asking such a fundamental question but it would be more foolish not to ask :)
I have been using SubSonic 2.x for years and love it (Thanks Rob and co.).
I have started a pilot project using SubSonic 3.0.0.4 and have chosen the LINQ T4 Templates (excuse me if I have the terminology wrong).
Now I am new to LINQ but I am doing OK working out how to build the queries.
What I am REALLY struggling with is how to create and update data with the new toolkit.
Previously it was super simple where I could:
'new' an object if I didn't have one
or Fetch or construct an existing one by id
set some properties
then 'Save()' it
Fantastic and saved me hours.
Now in the new toolkit some things seem to be the same like:
creating an object
setting some properties
but right now some things seem a lot harder like:
Loading an object seems to be:
db.Product.FirstOrDefault(x => ProductID.Id == 123);
Inserting seems to be:
db.Insert.Into<Northwind.Region>(
x => x.RegionID,
x => x.RegionDescription)
.Values(6, "Hawaii").Execute();
Updating an object seems even harder:
db.Update<Product>()
.Set(x => x.UnitPrice == 100, x => x.ProductName == "Test")
.Where(x => x.ProductID == 1).Execute();
The documentation (http://subsonicproject.com/docs/Linq_Updates) talks about using the Repository but that just doesn't exist/get generated with the T4 templates I am using.
So any help to let me know that:
I have obviously set this up wrong
I have no idea what I am doing and the way to do it is ... insert answer here
I understand it correctly and should just suck it up
would be greatly appreciated.
If any more info is needed please let me know.
Thanks in advance.
Mark
---- Update ----
To summarise the answer from Denis:
LINQ is a query language not an ORM
You can get to the Repository object via:
var repo = new SubSonic.Repository.SubSonicRepository(db);
Hmm.. I migrated one of my projects to the SubSonic 3 too but frankly have not had any troubles saving the entities. I use the same ActiveRecord techniques and it still works great for me. For example, to retrieve an entity I am issuing:
var product = new Product(p => p.Id == 123);
For inserting:
var product = new Product();
product.RegionID = 6;
product.RegionDescription = "Hawaii";
product.Save();
Updating:
product.UnitPrice = 100;
product.ProductName = "Test";
product.Save();
As you can see you can still use the same Save() method.
So, not really sure why you try to do that through the 'db' context even though it can be used too :) Am I missing something?

Resources