NSTableView bound to NSSearchField - How to relate selection to unfiltered datasource - nstableview

I'm stumped. My Swift app uses an NSTableView bound to an array controller, and uses a bound NSSearchField as a text filter. My problem is that the table's selectionIndexes binding gives me the selected indexes in the filtered table, whereas I need the selected indexes in the unfiltered table.
Example... my table has 1000 rows and I want to select row 567. Rather than scroll down to row 567, I enter a few characters into the search box, and this reduces the number of rows to 17, and the row I'm interested in is now row 12. If I select row 12, how can my app figure out that row 12 corresponds to row 567 in my data array?

selectionIndexes of NSArrayController are indexes in arrangedObjects of the arrayController. arrangedObjects is the content of the arrayController, filtered by filterPredicate and sorted by sortDescriptors.

Related

How do I populate an empty column in my sql database?

How do I populate an empty column in my sql database?
I have a list that I want in the last column of my database. If I use executemany it just adds rows on the bottom of my database. Is there a way to fill it from the top? The column is currently populated with NULL values.
Just to be clear. I want the first item in the list to be put in the first row and item n on the list to be put into row n.
Thanks in advance
*Always take backup of your database, just incase you want to revert it back to original state.
Each row in your database table should have a unique primary key. As you mentioned you have a list to be uploaded in the last column, I assume you have some kind of relationship that distinguishes which list item goes to which row in the last column of the table.
You an update a single row by simple update syntax as below:
UPDATE table_name
SET last_column = somevalue_from_list
WHERE id = unique_row_id;
If you want to update all the rows with the same value then
UPDATE table_name
SET last_column = one_value_for_all_rows;
Follow the below suggestion only when you are using phpmyadmin to manage your tables:
If you want to update each row with the unique value from the list then my suggestion will be to export your table in csv format, open in excel like software and add your last column values in last column of each row and then import the changed table back to the database.
Hope this help.

create empty row in dbgrid

I wanted to insert several lines to database using DBGrid.
on my query, I selected for example:
select * from cust where id='0';
that code will return no record at all so my dbgrid will not show anything but an empty row. Now I wanted to put in data in empty row with new data. However my data needs 2 lines from dbgrid. I wanted dbgrid creates an empty row right after I fill last column in first row. How do I code that? (without inserting the first row data because later I'll insert everything with a seperated button).
thanks!
you can add records in your table with NULLin each column.
For example, suppose the table where the DBGrid is binded to has 4 columns, than you can try this code to add empty records
Query1.InsertRecord([null, null, null, null]);
With this code you can add as many empty records as you like in the DBGrid
That is assuming that the query component you are using supports the InsertRecord method...

Moving rows in sqlite database

I have a table that is actually a ranking list. I want to give user a chance to rearrange that top the way he wants, ergo, allow him to move the rows in that table. Should I create a separate column that would hold the place, or can it be done using embedded order in table?
The documentation says:
If a SELECT statement that returns more than one row does not have an ORDER BY clause, the order in which the rows are returned is undefined.
(This is true for all SQL databases.)
So you cannot rely on the order that the rows happen to be stored in; you have to use some value in some table column.

How to Access a Column Value in a Select List within a Tabular Form for Each Row in Oracle APEX

Within a tabular form using the following sample query, i.e.:
select
"EMPNO",
"EMPNO" EMPNO_DISPLAY,
"ENAME",
"HIREDATE",
"SAL",
"DEPTNO",
"MY_LOV"
from"#OWNER#"."EMP"
I would like to access for each row in my tabular form, the EMPNO value for that row, within a select list (query based LOV) within "MY_LOV" column.
So basically, the column MY_LOV within my tabular form, would be a select list (query based LOV) where MY_EMPNO = :EMPNO (first column in select query above), for each row in the tabular form.
First make a named LOV in your shared components.
Then go to the column attributes of the MY_LOV column and for Display As select Select List (named LOV).
Then in the List of Values region you can specify which LOV you just created.
The value of the select list will be the value of the MY_LOV column in your query, which means this value should also be EMPNO:
select
"EMPNO",
"EMPNO" EMPNO_DISPLAY,
"ENAME",
"HIREDATE",
"SAL",
"DEPTNO",
"EMPNO" "MY_LOV"
from "#OWNER#"."EMP"

SQLite. Insert a value depending on the value of another column

E.g., I insert a value to the column called SALARY. If the inserted value is greater than 1000, I'd like to insert the string HIGH to the column called RANK and LOW otherwise.
Can I do that using SQLite?
Use Trigger BEFORE INSERT and there put your logic (if bigger than 1000, put HIGH etc.). In "before" triggers you have access to data that is about to be inserted so you can check value easily. Doc: https://www.sqlite.org/lang_createtrigger.html

Resources