Let's say, I have a custom form in frontView, with "txtroles" multi-select HTML element.
I submit it to my "UpdateProjectUsersAction" and would like to save it to my "project_user_roles" which have project_id (foreign id), role_name (text), userid (foreign id).
Now, I would like "UpdateProjectUsersAction" to save each multiple values added in "txtroles" to each new rows in my "project_user_roles" table
Related
Below is my example code:
db = QSqlDatabase.addDatabase('QSQLITE')
db.setDatabaseName('book.db')
db.open()
model = QSqlQueryModel()
model.setQuery("SELECT * FROM card")
self.tableView.setModel(model)
I am using QSqlQueryModel, Qtablevie, Sqlite3, and able to view all rows in my table. But i want to view only last two rows of my table which are newly inserted rows in to the table. The table has no "id" field and it has numaric and text fields. How is it possible?
Below is the table image:
If you want to get the last 2 elements ordered by any field that indicates the insertion order, in your case "rowid", then you have to use a filter in the SQL command like this:
model.setQuery("SELECT * FROM card ORDER BY rowid DESC LIMIT 2")
Another possible option is to filter the table using QSortFilterProxyModel but it is more inefficient.
I couldn't make the title clearer, but here's what I need help with.
I have a custom page type [1] for Leaders which includes 2 fields: Name, and Title. This holds the list of all leaders at the company.
I have another custom page type [2] for Speaking Events, which includes a field called Speaker to display the speaker's name and title. This field was set up as a drop-down list with data source from a SQL Query to query the Leaders data in [1].
Select LeadersID, Name, Title from co_leaders order by Name
I got it work fine - the drop-down displays a list of Name. However, what I wanted to display in the drop-down option is: Name, Title (not just Name) like below so that I only pick one and have both Name and Title. Is it possible to do this?
John Doe, CEO
Jane Doe, CFO
Hope it's clear and thanks for your input!
This is the SQL you are looking for:
SELECT LeadersID, Name + ', ' + Title FROM co_leaders ORDER BY Name
You need to do a concatenation of the column values (Name and Title), as opposed to selecting the columns separately.
EDIT: This is assuming that Name and Title are not nullable fields.
If there is a NULL value in any of the concatenated fields, the end value will be NULL. In this case, you will need to use COALESCE (or an equivalent function) to define an alternative value. For example:
SELECT LeadersID, Name + ', ' + COALESCE(Title, 'Member') FROM co_leaders ORDER BY Name
I am trying to model a table of content which has a timestamp, ordered by the timestamp. However I want that timestamp to change if a user decides to edit the content, (so that the content reappears at the top of the list).
I know that you can't change a primary key column so I'm at a loss of how something like this would be structured. Below is a sample table.
CREATE TABLE content(
id uuid
category text
last_update_time timestamp
PRIMARY KEY((category, id),last_update_time)) WITH CLUSTERING ORDER BY (last_update_time);
How should I model this table if I want the data to be ordered by a column that can change?
2 solutions
1) If you don't care having update history
CREATE TABLE content(
id uuid
category text
last_update_time timestamp
PRIMARY KEY((category, id))
// Retrieve last update
SELECT * FROM content WHERE category = 'xxx' AND id = yyy;
2) If you want to keep an history of updates
CREATE TABLE content(
id uuid
category text
last_update_time timestamp
PRIMARY KEY((category, id),last_update_time)) WITH CLUSTERING ORDER BY (last_update_time DESC);
// Retrieve last update
SELECT * FROM content WHERE category = 'xxx' AND id = yyy LIMIT 1;
I have an Access database. Here is the setup for a few tables.
id - companyID (autonumber) PK, company (text), firstName (text), lastName (text)
category - companyID (number) combined PK with category, category (text)
salesmen - companyID (number) combined PK with code, code (text)
There is a 1-many relationship between id and category and between id and salesmen.
If I have a spreadsheet with columns of company, firstName, lastName, category1, category2, category3, salesman1, salesman2, how could I import the columns into the appropriate tables?
My first idea was to import the spreadsheet and then append company, firstName and lastName to the id table. Then I would join the imported spreadsheet with the id table to create a new table with all of the spreadsheet columns plus the auto generated companyID. Then I could append companyID and category1 to the category table. Then do the same for category2 and 3 and so on.
This seems really complicated if I have a lot of spreadsheets to import. Also, the person who will be importing the spreadsheets isn't a programmer, so she wants it to be as user-friendly as possible.
Is there a better way to import these spreadsheets?
Thanks!
What I would do is create another table to import the raw data into, then INSERT the data from there into the relevant tables.
DoCmd.RunSQL ("DELETE * FROM ImportDataTable;")
DoCmd.TransferSpreadsheet acImport, acSpreadsheetTypeExcel12, "ImportDataTable", "C:\exceldata.xls"
The second line in Access VBA will import the data into the table called ImportDataTable (the ImportDataTable column names should be F1, F2, F3, etc.
Then use an append query (INSERT INTO) for each table that some of the ImportDataTable data needs to go in to. All this code can be put behind a button on a form so that the user(s) only need to press a button when new data is available.
In my application I have lists which have items in them, they would look like that
1. list uuid: b1d19224-ebcc-4f69-a98e-4096a4b28121
1. item
2. item
3. item
2. list uuid: 54b17b3a-5d83-4aec-9e7e-16bff1ba336b
1. item
Those items are indexed by there numbers. What I would like to do is add items to those lists, but not just at the end of the list but sometimes also after a specific item for example after the first item.
The way I thought of doing that is by giving those items a unique id looking like that: (uuid of list).(number of item) for example b1d19224-ebcc-4f69-a98e-4096a4b28121.1. So every time I would like to add a new item it's either I would add it to the end of the list or after some item giving the rest of the items after that new an index+1 for example (uuid of list).(number+1).
Is there another way of accomplishing that, or should I do it like that?
If you want to insert your items in your lists sorted on the unique item number, you should use CQL3 based composite primary keyed column family.
create table list (
partkey varchar,
item_num int,
id varchar,
data varchar,
PRIMARY KEY (partkey, item_num)
) with clustering order by (item_num desc);
Where the first part of primary key would server as the partition key and the second one serves as the sorting value. Have a look at the following link :
http://rollerweblogger.org/roller/entry/composite_keys_in_cassandra