The right way to perform check for existing rows? - database

I have a table of tags in the database, where it has id and tag_name. I will use tags for the search of associated pictures, and to add those pictures I use a form where tags are entered separated by commas and a picture is uploaded. Before creating associations I need to check if there are new tags, that do not exist in my database. Should I be quarrying full list and performing separation within code (flask server) or it would be better to check each tag with database query?

Related

What is the best way to integrate attachments in SharePoint?

I am working on a Contract / Invoicing project, I made the contract table and I need to add the contracts in PDF or Word form.
I wonder what is the best way to integrate attachments in sharepoint, do I have to use a library or is it better to work with an attachment column in the contract list
Several benefits to each.
Use a library when:
The focus is the document. The metadata/columns is secondary.
Each document is unique, not part of a set.
The content of the document needs to be indexed for search, and uniquely found. (The link in the search results points to the document.)
Use a list with attachments when:
The focus is the metadata/columns and there may be zero or many related documents.
You need a list item even if there is no document, or no document yet.
It's OK when you search for a keyword found in one of the documents and you get the list item returned, not the document. (You would then need to open each attachment to find the search for term.) I.e. the link in the search results points to the list item, not the document.)
Use a Document Set when:
You need a focus on a set of documents, kind of like a folder with metadata that contains zero to many files.
You need to automatically create a collection of documents each time you create a new Document Set. (New hire form, parking permit, photo id appointment, training schedule, etc.)
You like having a "home page" / information panel for each set of documents.

Relational mapping of files and entities in the database

i'm working on a new project and looking into a good approach/ Best practise for file storage and how to efficiently map the files to several resources in a relational data model.
Note: All files are uploaded on a filesystem (not a database)
Option 1
Creating a Files table to store meta data of each file and create a relation with each resource (e.g. user_files, product_files, ... )
Questions: Will all files be stored in a single table? If I want to fetch the user avatar I have to search in a table that also contains product images or pdf documents?
Option 2
Store the needed file meta data with each resource.
Downside: each resource can only have 1 image. (good for user avatar?)
Option 3
Files are created using a hash of the resource (e.g. user_1243_avatar)
No relation will be stored and the url will be build when the resource is fetched.
Are there other options to consider?
all input is welcome.
It's good that you store files in the filesystem. I used option 1 in a recent project and would recommend it.
If I want to fetch the user avatar I have to search in a table that also contains product images or pdf documents?
You make it sound as if you'll have to do a table scan. In my DB, a user's avatar was indicated by an avatar_file_id in the users table, so I could join from users to files directly using an index.
Your user_files sounds too generic. Users could have different files for different purposes, are you just going to lump them all together? Would you create a table person_to_person to lump together friends, marriages, manager/employee, parent/child, etc? I wouldn't.
Create different tables for different purposes, e.g. a one-to-one table user_avatar (or denormalize it into your users table). Some more examples might be product_images, product_specs, product_helpfiles, etc.

Create multiselect lookup in salesforce using apex

I want to create a multi-select Contact Lookup.
What i want :
When user clicks on a lookup then he should be able to select multiple contacts from that.
What i have done:
I have created an object and a field inside that object using both
"Lookup" and
"MasterDetail Relationship" and
"Junction Object"
When i try to use this Field for any input text/Field then it always provides an option to select only one value from lookup but i want to have an option to select multiple.
Even in the Junction object i have created 2 master-detail relationships still lookup allows only one value to be selected.Moreover it makes the field mandatory which i don't want.
Links that i followed:
http://success.salesforce.com/questionDetail?qId=a1X30000000Hl5dEAC
https://ap1.salesforce.com/help/doc/user_ed.jsp?loc=help&section=help&hash=topic-title&target=relationships_manytomany.htm
Can anybody suggest me how to do this.
Its same as we use Email CC/BCC under Send Email option for any Lead.
Even you use a junction object a lookup is just that, it references (looks up to) one other record: when you create a record on the junction object you still have to set each lookup individually and you're still creating only one record.
Master Detail relationships are essentially lookups on steroids, one object becomes the child of the other and will be deleted if the parent object is deleted, they're not going to provide an interface to lookup to many records at once.
If you're not a developer then your best bet is to either just create on junction object record at a time, or look into using dataloader. You could prepare your data in Excel or similar and then upload all the records into Salesforce in one go.
If you are a developer, or have developers at your disposal, then what we've done in the past is create a Visualforce page to do the job. So if, for example, you wanted to link a bunch of contacts up to an Account, we'd have a single account lookup field on the page, then some search fields relating to fields on the contact. Using a SOQL query you can then find all contacts matching the search parameters and display them in a list, where you may want to provide checkboxes to allow the user to select the contacts they want. Then it's just a case of looping through the selected contacts, setting their Account field to be the chosen account.
There are areas in Salesforce (such as the send Email functionality you mentioned) where it's clear to see that bespoke work has been done to fulfil a specific task — another instance of what you want is in the area where you can manage campaign members. This is the model I've copied in the past when implementing a Visualforce page as described.
Good luck!
For adding multiple junction objects at one time, the only solution we have found is a custom Visualforce page, as described by LaceySnr.
For a slightly different problem, where we need to assign many of object B to object A, We have trained our users to do this with a view on object B. We are assigning Billing Accounts (B) to Payment Offices (A). The view on Billing Account has check boxes on the left side. The user checks the Billing Accounts to be assigned, then double-clicks on the Payment Office field on any of the checked rows. A pop-up asks if you want to update only the single row or all checked rows. By selecting 'all checked rows', the update is done to all of them.
The view is created by the user, who enters the selection criteria (name, address, state, etc.). All user-created views are visible only to them.

Custom query which returns to data block output in Oracle Forms Builder?

I have these tables
BOOKS
ID | GENREID(number) | COUNTRYID(number) |
GENRES
ID | TITLE
COUNTRIES
ID | TITLE
In my form BOOKS, I need to display:
ID GENERES.TITLE COUNTRIES.TITLE
All I need is to JOIN tables or SELECT data from all tables and display it. It seems that this is impossible with Oracle forms designer. My data block output displays data from the BOOKS table with inserted ids, but not with titles corresponding to those ids from separate tables (e.g. GENRES, COUNTRIES). I can't find where to put a custom query to data block.
I am using latest oracle dev suite home. How do I do this?
There's two common ways to do this:
Use a post-query trigger to populate non-database display fields and an LOV to allow them to insert and update those fields.
Create a view in the database and base your block on that.
The first one is the easiest but they won't be able to search on those non-database fields without a lot of extra work.
The second option allows search but adding and updating data in a view introduces some problems. I usually use an on-insert, on-update, on-delete, and on-lock trigger to handle those function manually and modify the base tables.
http://sheikyerbouti.developpez.com/from_clause/from_clause.htm
--> Read the Step 3
I'm using that one a lot. With that you can build your own queries to Forms and also get block which you can insert/update/delete (of course to one table). And this is how I for example do block which has like user id and user name fields.
But at least in my Forms version it's not possible to change query in run time because it's changing data_source_type back to default.

Full-text Search on Joined, Hierarchical Records in SQL Server 2008

Probably a noob question, but I'll go for it nevertheless.
For sake of example, I have a Person table, a Tag table and a ContactMethod table. A Person will have multiple Tag records and multiple ContactMethod records associated with them.
I'd like to have a forgiving search which will search among several fields from each table. So I can find a person by their email (via ContactMethod), their name (via Person) or a tag assigned to them.
As a complete noob to FTS, two approaches come to mind:
Build some complex query which addresses each field individually
Build some sort of lookup table which concatenates the fields I want to index and just do a full-text query on that derived table.
(Feel free to edit for clarity; I'm not in it for the rep points.)
If your sql server supports it you can create an indexed view and full text search that; you can use containstable(*,'"chris"') to read all the columns.
If it doesn't support it as the fields are all coming from different tables I think for scalability; if you can easily populate the fields into a single row per record in a separate table I would full text search that rather than the individual records. You will end up with a less complex FTS catalog and your queries will not need to do 4 full text searches at a time. Running lots of separate FTS queries over different tables at the same time is a ticket to query performance issues in my experience. The downside with doing this is you lose the ability to search for Surname on its own; if that is something you need you might need to look at an alternative.
In our app we found that the single table was quicker (we can't rely on customers having enterprise sql at hand); so we populate the data with spaces into an FTS table through an update sp then our main contact lookup runs a search over the list. We have two separate searches to handle finding things with precision (i.e. names or phone numbers) or just for free text. The other nice thing about the table is it is relatively easy and low cost to add further columns to the lookup (we have been asked for social security number for example; to do it we just added the column to the update SP and we were away with little or no impact.
One possibility is to make a view which has these columns: PersonID, ContentType, Content. ContentType would be something like "Email", "PhoneNumber", etc... and Content would hold that. You'd be searching on the Content column, and you'd be able to see what the person's ID is. I'm not 100% sure how full text search works though, so I'm not sure if you could use that on a view.
The FTS can search multiple fields out-of-the-box. The CONTAINS predicate accepts a list of columns to search. Also CONTAINSTABLE.

Resources