in my table key_m, there are 4 columns operation which is char(1),token_type varchar(4) which will hold value soft or hard, department_code varchar(20), and last column default boolean
while inserting the record in key_m it should check(operation,token_typr, and department_code) that the values we are trying to insert are already present or not if not present then default should be true else it should be false.
for the first unique record insertion default value should be true, for the duplicate record entry value should be false.
example:-
| department_code | operation | token_type | ----- default|
| 1 | e | soft | t |
| 1 | e | hard | t |
| 1 | e | soft | f |
| 1 | e | hard | f |
| 1 | e | soft | f |
| 1 | e | soft | f |
I have implemented a tagging system in my application, using Postgres 9.6. There are three tables.
Projects
Table "public.project"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+---------------------------------
id | integer | | not null | nextval('tag_id_seq'::regclass)
name | character varying(255) | | not null |
user_id | integer | | |
Tags
Table "public.tag"
Column | Type | Collation | Nullable | Default
-------------+-----------------------------+-----------+----------+---------------------------------
id | integer | | not null | nextval('tag_id_seq'::regclass)
tag | character varying(255) | | not null |
user_id | integer | | |
is_internal | boolean | | not null | false
Project tags
Column | Type | Collation | Nullable | Default
------------------+-----------------------------+-----------+----------+-----------------------------------------
id | integer | | not null | nextval('project_tag_id_seq'::regclass)
tag_id | integer | | not null |
project_id | integer | | | |
user_id | integer | | not null |
Now I want to get a list of all the projects, annotated with a column that indicates (for a particular tag) whether it has that tag.
So I'd like the results to look like this:
id name has_favorite_tag
1 foo true
2 bar false
3 baz false
This is my query so far:
select project.*, CASE(XXXX) as has_project_tag
from project p
join (select * from project_tag where tag_id=1) pt on p.id=pt.project_id
I know that I want to use CASE to be true when the length of project_tag matches is greater than 0 - but how do I do this?
(In reality the project table has many more fields, of course.)
Here's a possibility (unfiltered for tag_id; add to inner select if necessary):
select project.*, exists(select * from project_tag where id=project.id) as has_project_tag from project;
My insert query is,
insert into app_library_reports
(app_id,adp_id,reportname,description,searchstr,command,templatename,usereporttemplate,reporttype,sentbothfiles,useprevioustime,usescheduler,cronstr,option,displaysettings,isanalyticsreport,report_columns,chart_config)
values
(25,18,"Report_Barracuda_SpamDomain_summary","Report On Domains Sending Spam Emails","tl_tag:Barracuda_spam AND action:2","BarracudaSpam/Report_Barracuda_SpamDomain_summary.py",,,,,,,,,,,,);
Schema for the table 'app_library_reports' is:
Table "public.app_library_reports"
Column | Type | Modifiers | Storage | Stats target | Description
-------------------+---------+------------------------------------------------------------------+----------+--------------+-------------
id | integer | not null default nextval('app_library_reports_id_seq'::regclass) | plain | |
app_id | integer | | plain | |
adp_id | integer | | plain | |
reportname | text | | extended | |
description | text | | extended | |
searchstr | text | | extended | |
command | text | | extended | |
templatename | text | | extended | |
usereporttemplate | boolean | | plain | |
reporttype | text | | extended | |
sentbothfiles | text | | extended | |
useprevioustime | text | | extended | |
usescheduler | text | | extended | |
cronstr | text | | extended | |
option | text | | extended | |
displaysettings | text | | extended | |
isanalyticsreport | boolean | | plain | |
report_columns | json | | extended | |
chart_config | json | | extended | |
Indexes:
"app_library_reports_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
"app_library_reports_adp_id_fkey" FOREIGN KEY (adp_id) REFERENCES app_library_adapter(id)
"app_library_reports_app_id_fkey" FOREIGN KEY (app_id) REFERENCES app_library_definition(id)
When I execute insert query it gives error:ERROR: syntax error at or near ","
Please help me to find out this error.Thank you.
I'm fairly certain your immediate error is coming from the empty string of commas (i.e. ,,,,,,,) appearing at the end of the INSERT. If you don't want to specify values for a particular column, you can pass NULL for the value. But in your case, since you only specify values for the first 6 columns, another way is to just specify those 6 columns names when you insert:
INSERT INTO app_library_reports
(app_id, adp_id, reportname, description, searchstr, command)
VALUES
(25, 18, 'Report_Barracuda_SpamDomain_summary',
'Report On Domains Sending Spam Emails', 'tl_tag:Barracuda_spam AND action:2',
'BarracudaSpam/Report_Barracuda_SpamDomain_summary.py')
This insert would only work if the columns not specified accept NULL. If some of the other columns are not nullable, then you would have to pass in values for them.
I'm new to JPA and I am having some difficulty creating some entities.
In the application I am building it is possible to classify some entities according to some area and subarea defined in a database.
The relevant tables are these four ones:
1) classification
+-------------+-----------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+-----------------------+------+-----+---------+----------------+
| ID | int(11) unsigned | NO | PRI | NULL | auto_increment |
| pID | int(11) unsigned | NO | MUL | NULL | |
| reference | varchar(300) | NO | | NULL | |
| link | varchar(255) | YES | | NULL | |
+-------------+-----------------------+------+-----+---------+----------------+
2) cls_area_map
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| class | int(11) unsigned | NO | MUL | NULL | |
| idarea | int(11) unsigned | NO | MUL | NULL | |
| subarea | int(11) unsigned | YES | MUL | NULL | |
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
+---------+------------------+------+-----+---------+----------------+
3) area
+--------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------------+------+-----+---------+----------------+
| idarea | int(11) unsigned | NO | PRI | NULL | auto_increment |
| label | varchar(255) | NO | UNI | NULL | |
+--------+------------------+------+-----+---------+----------------+
4) subarea
+-------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------------+------------------+------+-----+---------+----------------+
| area_idarea | int(11) unsigned | NO | MUL | NULL | |
| label | varchar(255) | NO | UNI | NULL | |
| ID | int(11) unsigned | NO | PRI | NULL | auto_increment |
+-------------+------------------+------+-----+---------+----------------+
In classification I store general classification information, and in cls_area_map I try to connect the general information to the areas of classification (defined in area and subarea).
When I try to add the classification-area mapping information to my Classification and my Cls_area_map entity classes I run into trouble.
I get the error:
An incompatible mapping has been encountered between [class Entity.Classification] and [class Entity.Cls_area_map]. This usually occurs when the cardinality of a mapping does not correspond with the cardinality of its backpointer..
I'm not sure what I'm doing wrong about the cardinality. This is what I added to Classification to create the relationship:
#OneToMany(mappedBy = "id")
private List<Cls_area_map> cls_area;
and in Cls_area_map:
#JoinColumn(name = "class",referencedColumnName = "ID")
#ManyToOne(optional=false)
private Classification classy;
Any explanations/hints?
(and what is meant by backpointer?)
mappedBy indicates that the entity in this side is the inverse of the relationship. So entity name should be used instead of foreign key.
The doc says
mappedBy refers to the property name of the association on the owner
side.
It is classy in your case, so use
#OneToMany(mappedBy = "classy")
private List<Cls_area_map> cls_area;
See also:
mappedBy
i want to build an ACL system for my application which have the following requirement.
Users will be assigned single or multiple role. (Admin, Staff) etc.
Role will have permissions.(Send_Invoices, Send_mail, Delete_Invoices, Send_Estimate) etc.
User will be assigned custom permission apart from the role it inherits.
my database structure for ACL is as follows
role:
+----------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| roleName | varchar(50) | NO | UNI | NULL | |
+----------+-------------+------+-----+---------+----------------+
permission:
+----------------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| permissionName | varchar(50) | NO | | NULL | |
| permissionKey | varchar(50) | NO | UNI | NULL | |
+----------------+-------------+------+-----+---------+----------------+
role_permission
+---------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| role_id | int(11) | NO | MUL | NULL | |
| permission_id | int(11) | NO | | NULL | |
+---------------+---------+------+-----+---------+----------------+
user_role
+---------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| role_id | int(11) | NO | | NULL | |
+---------------+---------+------+-----+---------+----------------+
user_permission
+---------------+---------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+---------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| permission_id | int(11) | NO | | NULL | |
+---------------+---------+------+-----+---------+----------------+
i have migrated to Zend Framework, and having problem deciding wether Zend_Acl allows me to implement the current structure. my question is.
is it possible for me to implement the ACL with current database structure to do the needful in Zend Framework?
is there any better implementation that could allow me to achieve what i want in zend framework?
i will be grateful if someone could provide me a way to get started with what i need to do. any resources, links that could help me?
thank you.
Well I think this structure is really good , to get this working you had to do 2 steps
1-Setup all the databases and requirements
2- create an ACL plugin that determine the user's role and his permissions
some example with doctrine support :
Developing a Doctrine-backed ACL helper TDD-style, part 1
Developing a Doctrine-backed ACL helper TDD-style, part 2
another simple ACL :
Dynamic custom ACL in zend framework?
Why not use the Grants/Roles system already in the database?