I'm creating a simple application, there is a table with file names, and a column with IDs of users allowed to read it, for example:
|FILES |USERS |
|my.txt|1,3,5 |
|fo.txt|3,4,17|
|ba.jpg|13,31 |
Is it right this way for creating user groups?
What is the right SQL statement to retrieve files allowed to user "3"?
You shouldn't combine multiple values in one field.
Normal approach is:
|FILES |USERS|
|my.txt|1 |
|my.txt|3 |
|my.txt|5 |
|fo.txt|3 |
|fo.txt|4 |
|fo.txt|17 |
|ba.jpg|13 |
|ba.jpg|31 |
So if you want a list of files for user 3, you do:
SELECT Files FROM Table WHERE User='3';
To check users for a file,
SELECT Users FROM Table WHERE File='my.txt';
Also common is to avoid repeating long strings, creating a new table CREATE TABLE FileNames (ID INTEGER PRIMARY KEY, Filename) and always referring ID instead of names in other tables. But that should be a performance evaluation made by you.
You should normalize the database. So you'll have
|FILE |USER|
|my.txt| 1|
|my.txt| 3|
|my.txt| 5|
|fo.txt| 3|
...
That is simple normalization of the table you've shown. It does not involve any groups, but your original table didn't either.
You should add separate 'groups' table:
|OID|group_id|user_id|
| 1| 1| 1|
| 2| 1| 2|
and reference this group in your files table. If you want to check specific user, it would be something like
select FILES from files join groups on files.group_id = groups.group_id where groups.user_id = 3
Related
When I prepare for my exam, I meet the following statement:
If file1 and file2 are hard linked, and two processes open file1 and file2,
their read/write pointer keeps the same.
Which, according to the answer (no explanation), is wrong. So I searched google, and found something different.
This link: https://www.usna.edu/Users/cs/wcbrown/courses/IC221/classes/L09/Class.html Says the read/write pointer is in the (system wide) open file table.
But this link http://www.cs.kent.edu/~walker/classes/os.f08/lectures/Walker-11.pdf
Says the pointer is in the per process file table.
Which one is true?
IHMO, the read/write offset clearly has to be a per process property. You could easily crash other proceses if this was a system wide per file property. This is my understang, but I'd rather have this confirmed by an informed source.
I took a look at the 1986 AT&T book "The design of the Unix Operating System" by Maurice J. Bach, which I consider a informed source.
In topic 2.2.1 An Overview of the File Subsytem it sais:
... Inodes are stored in the file system ... The kernel reads them
into an in-core inode table when manipulating files ... The kernel
contains two other data structures, the file table and the user
file descriptor table. The file table is a global kernel
structure, but the user file descriptor table is allcated per
process ... The file table keeps track of the (read/write) byte
offset ...
This would contradict my statement. But then, clarification can be read in topic 5.1 OPEN, pages 92ff. Figure 5.3 shows an example of a process having done three opens, two of them being for the same file, /x/y/z (I simplfy the naming here, and in the illustration below).
User File
Descriptor Table File Table inode Table
+--------------+ +------------+ +------------+
0| | | | | |
+--------------+ | . | | . |
1| | | . | | . |
+--------------+ | . | | . |
2| | +------------+ | |
+--------------+ +-->| read offset|----+ | |
3| | | +------------+ | | |
+--------------+ | | | | +------------+
4| |---+ | . | +->| inode of |
+--------------+ | . | +--->| /x/y/z |
5| |----+ | . | | +------------+
+--------------+ | +------------+ | | . |
6| |-+ +->| read |----+ | . |
+--------------+ | +------------+ | | | . |
| . | | | . | | | +------------+
| . | | | . | | +->| inode of |
| | | | . | | | /a/b |
+--------------+ | +------------+ | +------------+
+---->|write offset|--+ | . |
+------------+ | . |
| . | | . |
| . | | . |
+------------+ +------------+
The final answer is in the text following figure 5.3 on page 94:
Figure 5.3 shows the relationship between the inode table, file
table, and user file descriptor table structures. Each open
returns a file descriptor to the process, and the corresponding entry
in the user file descriptor table points to a unique entry in the
kernel file table even though one file (/x/y/z) is opened twice.
To answer your question: The read/write offset is kept in the kernel file table, not in a per process table, but a unique entry is allocated upon each open().
But, why is there a kernel file table? After all, the read/write offsets could have been stored in the per process user file descriptor table, instead of in a kernel table, couldn't they?
To understand why there is a kernel file table, think of what the dup() and fork() functiones do with respect to file descriptors: They duplicate the state of an open file. Under a new file descriptor in the same process, dup(), or under the same file descriptor (number) but in a duplicated user file descriptor table in the new (child) process. In both cases, duplicating the state of an open file includes the read/write offset. So for these cases, more than one file descriptor will point to a single file table entry.
Yihui Xie's Bookdown book https://bookdown.org/yihui/bookdown/tables.html is very clear that the cross -referencing system requires adaptations for non-kable tables. The last paragraph in this section is key, but it is (to my lay mind) inscrutable, and I would appreciate an example or two to follow.
To make matters slightly more complicated, my project uses Rchunks, which may complicate the task a bit more.
But,does anyone have examples of bookdown crossref code (perhaps including Rchunks, Rmd calls to those Rchunks or \#ref(tab:...)) that they would share, and which do not call kable?
No entirely sure what you are asking but here is an example of a manually typed table that works with bookdown:
R includes a lot of advanced mathematical functions. Table \#ref(tab:mathfunctions) shows a list of the most common functions.
Table: (\#tab:mathfunctions) Common mathematical functions in R.
| Function | Explanation | Example|
|----------|------------|-------------|
| `abs(x)` | Absolute value| `abs(-3) = 3`|
| `sqrt(x)` | Square root | `sqrt(9) = 3` |
| `log(x)` | Natural logarithm | `log(10) = 2.303` |
| `log10(x)` | Base 10 logarithm | `log10(10) = 1` |
| `log(x, base=2)` | Base 2 logarithm | `log(10, base=2) = 3.322` |
| `exp(x)` | Exponential function | `exp(1) = 2.718` |
R also allows you to yada yada yada.
When reading 20+ columns horizontally, it gets hard on the eyes. I've been trying to find a way to display output of a single search result row as a scrollable vertical columnName:columnValue list:
+-------------------------+-+
| First_Name | John | |
| Last_Name | Doe | |
| Birthdate | 01011970 | |
| Last_login | 01012015 |X|
+-------------------------+-+
Is this possible?
This is functionality you can push to the database. For example if your DB is oracle 11g, you can use the unpivot feature.
Create a multicolumn list box with the below query.
select column_name,column_values from customers
unpivot
(column_values for column_name in ("FIRST_NAME" ,"LAST_NAME"))
I'm trying to figure out how can i get that a simple Datagrid has splitted columns.
I need the following layout:
+-------------------+
| Destination |
+--------+----------+
| Dir 1 | Dir 2 |
+-------------------+
Any idea about how could I do it?
You can use a header renderer for the same. Customized renderers can be created.
I know that I can access a single element from a dictionary object with this format ${dict['KEY']}. Like this:
| | Log | ${dict['KEY']} |
And I can set a regular old scalar like this:
| | ${scalar}= | RFKeyword | "Yowp"
But if I try to set a dictionary element like this
| | ${dict['KEY']}= | RFKeyword | "Yowp"
I get "RFKeyword", "Yowp" in the variable, rather than the result of what RFKeyword produces when processing "Yowp" like I do with this
| | ${scalar}= | RFKeyword | "Yowp"
Assistance please
As you probably have figured out, you can't assign to a dictionary from a keyword. You need to very specifically follow the dictionary syntax. you can only return variables to lists or scalars.
Robot framework isn't a fully fledged programming language, and it shouldn't be. By using an intermediate scalar, non-technical testers should be better able to understand what it is doing.
I added this since a google search for "robot framework dictionary" has this question high up in the list.
Just create dictionaries with:
Create dictionary | ${my_dict} | a | b
Add to dictionaries with:
set to dictionary | ${my_dict} | c | d
And retrieve from dictionaries with:
${my_dict["a"]}
Or, if you need to not fail:
${my_dict.get('non-key','default value')}
You just need to rearrange the way you call it. So for your keyword where you want the returned data to go into your dictionary you need to do the following:
${scalar}= | RFKeyword | "Yowp"
Set To Dictionary | ${dict} | KEY | ${scalar}