Querying adjacent rows in Azure Mobile Services - asp.net

I'm working with Azure Mobile Services and have a table with GUIDs as its Primary Key (RecordId). I need to retrieve the previous and next rows of the table based on an ID.
Example of table:
| RecordId | RecordText |
|--------------------------------------|------------|
| 25892e17-80f6-415f-9c65-7395632f0223 | Hello |
| a53e98e4-0197-4513-be6d-49836e406aaa | Bye |
| e33898de-6302-4756-8f0c-5f6c5218e02e | Byebye |
| 3a768eea-cbda-4926-a82d-831cb89092aa | Wow |
Sample Input:
1) I enter a53e98e4-0197-4513-be6d-49836e406aaa
2) I enter e33898de-6302-4756-8f0c-5f6c5218e02e
Sample Output:
1) I'll get three results: 25892e17-80f6-415f-9c65-7395632f0223 (Previous), a53e98e4-0197-4513-be6d-49836e406aaa (Current), e33898de-6302-4756-8f0c-5f6c5218e02e (Next)
2) I'll get three results: a53e98e4-0197-4513-be6d-49836e406aaa (Previous), e33898de-6302-4756-8f0c-5f6c5218e02e (Current), 3a768eea-cbda-4926-a82d-831cb89092aa (Next)
How would I go about implementing this, and would I do this from the Node.js backend of from my ASP.NET? The use case here is a webpage where I can click Previous or Next buttons to go to the corresponding records.

Related

Update foreign key in Qt QSqlRelationalTableModel

I'm coding in python (PySide2), but the overall concept concerns the Qt Framework.
Here are two tables of mine:
Table "recordings":
| Column | Type |
| -------- | -------------------|
| id | int (primary key) |
| param1 | int |
| param2 | int |
| ... | int |
| paramN | int |
Table "analyzed_recs":
| Column | Type |
| -------- | -------------------|
| id | int (primary key) |
| rec_id | int (foreign key) | <-- Points to recordings.id
| paramN | int |
I need in my program to display param1 and param2 from the former. In Qt I used a QSqlRelationalTable to fulfill this objective:
def _init_db_models(self):
self.analyzed_recs_sql_model = QSqlTableModel(self, self.db)
self.analyzed_recs_sql_model.setTable("analyzed_recs")
rec_id = self.analyzed_recs_sql_model.fieldIndex('rec_id')
self.analyzed_recs_sql_model.setRelation(rec_id, QSqlRelation("recordings", "id", "param1"))
self.analyzed_recs_sql_model.setRelation(rec_id, QSqlRelation("recordings", "id", "param2"))
self.analyzed_recs_sql_model.select()
self.analyzed_data_table.setModel(self.analyzed_recs_sql_model)
This code works fine in displaying the desired fields.
However, when it comes to update a record in analyzed_recs:
record = self.analyzed_recs_sql_model.record()
record.remove(record.indexOf("id"))
record.setValue("rec_id", self.current_rec_id)
record.setValue("param1", self.param1)
record.setValue("param2", param2)
self.analyzed_recs_sql_model.insertRecord(-1, record)
self.analyzed_recs_sql_model.submitAll()
The column rec_id is not set (NULL) into the table (the other params are correctly inserted into the table).
On the contrary, if I avoid using QSqlRelationalTableModel and take QSqlTableModel instead, the insertion is performed correctly (as I expected), but I lose the INNER JOIN display feature.
I was thinking as a work around to create two distinct models, a QSqlRelationalTableModel only for displaying and a QSqlTableModel only for editing the data. However I don't like the extra workload of syncing the two.
I'm sure there is a Qt feature to achieve this, but unfortunately I'm missing it.
Any suggestion?
I've had the same problem using PYQT.
The record object returned by calling record() method has no fields named 'rec_id' because the QSqlRelationalTableModel changes it with the referenced field name 'param1'. We can verify the field names using:
fieldcount = record.count()
for i in range(fieldcount):
logging.info("field %s %s", i, record.fieldName(i))
so we need to add the field before assigning it:
record = self.analyzed_recs_sql_model.record()
record.remove(record.indexOf("id"))
record.append(QSqlField("rec_id"))
record.setValue("rec_id", self.current_rec_id)

SQLite sort by position in a String [] , when that String [] is a field

I have a table like below in Room, in a Android application, I use Raw Query to get data. Can it be sorted by second value in array sorting_field?
---------------------------------------------
| id | other_fields | sorting_field |
---------------------------------------------
| 1001 | … | ["24","0.02","2"] |
---------------------------------------------
Initially I did the sorting part in Repository with Transformations.switchMap, inside the function a MutableLiveData> and applied Collections.sort.
It worked like a charm:
Collections.sort(list, (o1, o2) -> Double.compare(Double.valueOf(o1.sorting_field().get(positionInList)), Double.valueOf(o2.sorting_field().get(positionInList))));
After Paging implementation, I took the sorting logic out, moved to queries builder and here I am.

How to write Kusto query to get results in one table?

I have 2 KQL queries and I want to combine them in order to display two rows as one result. Not just result of first query, then result of second query:
R_CL
| where isnotempty(SrcIP_s)
| project Message
| take 1;
R_CL
| where isempty(SrcIP_s)
| project Message
| take 1
See sample R_L below.I would like to see 2 rows as result, one with SrcIP_s not empty, and the second with SrcIP_s empty (in this case it will be always same one)
let R_CL = datatable ( SrcIP_s:string, Message:string)
["1.1.1.1" ,"one",
"" ,"two",
"2.2.2.2","three",
"3.3.3.3","four"];
R_CL
| project SrcIP_s, Message
A simple solution for this would be to use the union operator like this:
let query1 = R_CL
| where isnotempty(SrcIP_s)
| project Message
| take 1;
let query2 = R_CL
| where isempty(SrcIP_s)
| project Message
| take 1;
query1
| union query2;
I know this is an old request - but here's a sample query using views and a union for your single query:
Your two separate queries...
R_CL
| where isnotempty(SrcIP_s)
| project Message
| take 1;
R_CL
| where isempty(SrcIP_s)
| project Message
| take 1
would become:
let Query1 = view () {
R_CL
| where isnotempty(SrcIP_s)
| project Message
| take 1;
};
let Query2 = view () {
R_CL
| where isempty(SrcIP_s)
| project Message
| take 1
};
union withsource="TempTableName" Query1, Query2

JavaFX: Disable multiple rows in TableView based on other TableView

I'm creating an application in JavaFx. Right now I have two tableviews next to each other:
------------------------------------------------------------------------------
| TableView 1 | TableView 2 |
| | |
| | Entry 1 |
| | Entry 2 |
| | Entry 3 |
| | Entry ... |
| | Entry N |
------------------------------------------------------------------------------
I would like to copy items from TableView 2 to TableView 1, but at the same time, the entries that have been copied from TableView 2 need to be disabled (disable the row with setDisable or something similar). I do know how to copy the items from one tableview to another. The problem is that I do not know how to disable multiple rows when one or multiple entries have been copied to TableView 1.
I tried this with a RowFactory, like this:
productsInTransaction.setRowFactory(tv -> {
TableRow<Product> row = new TableRow<>();
row.disableProperty().bind(???);
return row;
});
Any help is much appreciated!
I'm not quite sure of the logic you're wanting, but if your row factory is attached to table 1, and you are disabling the row when the item is present in table 2, do:
row.disableProperty().bind(Bindings.createBooleanBinding(() ->
table2.getItems().contains(row.getItem()), table2.getItems(), row.itemProperty()));

DataGrid button - Invalid Postback or Callback

I have setup a DataGrid with a number of columns and a checkbox and column at the end of the row.
I am also changing the layout of the datagrid on the OnItemCreated event which changes the layout of the datagrid by expanding the rows with the "Rowspan" attribute and remove the extra columns and controls where they are no longer required.
The original datagrid layout was setup like this:
___________________________________________
| 1 | Employee Name | 01/08/10 |[] |[SAVE]|
| 1 | Employee Name | 02/08/10 |[] |[SAVE]|
___________________________________________
| 2 | Employee Name | 01/08/10 |[] |[SAVE]|
___________________________________________
| 3 | Employee Name | 04/08/10 |[] |[SAVE]|
| 3 | Employee Name | 05/08/10 |[] |[SAVE]|
| 3 | Employee Name | 06/08/10 |[] |[SAVE]|
___________________________________________
| 4 | Employee Name | 03/08/10 |[] |[SAVE]|
___________________________________________
And now it looks like this with the rows expanded, the controls removed and the datagrid columns deleted...
___________________________________________
| 1 | Employee Name | 01/08/10 |[] |[SAVE]|
| | | 02/08/10 | | |
___________________________________________
| 2 | Employee Name | 01/08/10 |[] |[SAVE]|
___________________________________________
| 3 | Employee Name | 04/08/10 |[] |[SAVE]|
| | | 05/08/10 | | |
| | | 06/08/10 | | |
___________________________________________
| 4 | Employee Name | 03/08/10 |[] |[SAVE]|
___________________________________________
The page displays when opened, and the paging control works as expected each time a user clicks on a page number.
However, when I click on the [SAVE] button for a particular employee, an error message shows a message similar "Invalid Postback or Callback". I understand that this is a result of the controls and columns that I have removed in the datagrid and the event validation does not match the orignal rendered items.
I do not want to remove the EnableEventValidation because it is a security issue.
I know I have to use the Render method to fix any changes that I have made before the page is displayed, but how do I resolve this postback issue?
Ok, lets see where the error comming from.
The GridView is use the __DoPostBack() javascript call and have no input by him self. So by him self is not send any input data from other cells.
Now I think that you do not have made custom DoPostBack calls - right ?
The second point that there is a validation is on ViewState Data.
Is by any change to use any UpdatePanel and in the middle you make any update that change this ViewState ?
What I suggest you to try is to send EnableViewState="false" on your GridView To see if you still get this error. This is not affect you because GridView in every update re-read the data that needs to created.
And the second point that you need to check, is the point that you change your data and afect the view state. Maybe by place it in other point solve the issue. From example if you have it on Page_Load maybe you need to move it on PageInit - or vise versa.
Hope this help.

Resources