what is good approach to make custom sql query (plain SQL syntax, not mixing with Python) with known table layout and map it to declarative description.
Tnx.
Good guy Jonathan Vanasco has answered this on sqlalchemy list,
If you have:
class MyTable(base):
pass
You could do
session.query( MyTable ).from_statement()
Related
In my current design, I have app_group, student and group_article:
To structurally ensure that a group_article is only associated with a student from that same group, the foreign keys "publisher" and "app_group" are taken from the join entity group_member (1) as opposed to having them issued from student and app_group individually. This way, someone with the right to insert new records into the database cannot introduce incoherent data such as adding an article that have been written by a student that isn't even in that group which would be poor design. Now, I want generalize this approach into multiple students or multiple groups. I now have group_message, group_message_in and group_message_out which is an inheritance chain (group_message is the base which is an abstract entity in Symfony, and both group_message_in and group_message_out extend it):
Initially, I was planning to embed the group foreign key on the base class (group_message) and have the sender/recipient (respectively on group_message_out and group_message_in) be taken from student directly:
However, this will leave the database vulnerable to incoherence as per the first example, eg: student from group A can be associated with a message that targets student from group B which is not desirable (only students from the same group can exchange group_message).
I'm well aware that I can amend this risk in code but I want a similar solution to (1) and to know if this is achievable with Doctrine since MySQL itself might have ways of solving a similar problem that aren't supported by Doctrine.
A relational solution to your problem would look something like this:
The integrity that you seek would be achieved by the PK-FK relationships and by assigning a student to a group using the groupName colums.
Your question then becomes something like "How can I use Doctrine to do the same thing?"
To the best of my knowledge Doctrine uses a set of PHP libraries to create what its proponents call a "persistence layer" that stores what it calls "Entities". With Doctrine, the term "Entity" is a synonym for "Class" in the OO paradigm.
In other words Doctrine stores classes in the data layer.
And now we can see the problem.
A relational schema is a structure of relations which is a completely different kind of artefact than a collection of classes.
The OO/Relational divide has been called an "impedance mismatch". Unfortunately this term obscures more than it reveals.
To quote from the Wikipedia article: "There have been some attempts at building object-oriented database management systems (OODBMS) that would avoid the impedance mismatch problem. They have been less successful in practice than relational databases however, partly due to the limitations of OO principles as a basis for a data model."
I suggest that you also review Ted Neward's article "The Vietnam of Computer Science."
This new answer shows the object-role model, the relational schema that it generates and the logic that is implied by the new constraint (shown by the red arrow)
The object- role model.
This is the logic that is asserted by the fact type Student(.id) is a member of Group(.name)
Now as the domain expert, you can read this verbalization and tell me whether it is True or False in your domain.
Please note that all I did as the modeler, was to change the constraint (shown by the red arrow) and the ORM tool called NORMA generated the new verbalization that you see here.
When the domain expert agrees that the model conforms to the requirements then it takes a few seconds to generate the SQL DDL that can then be used to create a new database schema in an RDBMS.
I've managed to identify the table from an attribute in SAP Netweaver ERP.
For example, Order Number (AUFNR) comes from table AUFK, and my question is: where do attributes like Material description (MATXT) come from?
I can't found this info via SAP user interface (from the little I know) and when I search on the internet for the structure, this attribute is also unidentifiable.
I post this question because I need to extract data to SQL Server tables, and I can't seem to find the source, via SAP user interface or on the internet. This might be probably a conceptual question about data organization in SAP.
The naming of this field (CO_XXXXX) unequivocally points out that this field relates to CO (Controlling) module, which should have been suggest you the proper direction.
The most probable tables this field can relate to are COCH and COCHP.
However, this fieldname is widely used in Plant Maintenance Notifications (PM-WOC-MN) as well.
Full list of structures and tables where it is used can be obtained in DD03L table. Query by field FIELDNAME, for example, like this, should give you the thing
SELECT *
INTO TABLE #DATA(result)
FROM dd03l As d3
JOIN dd02l AS d2
ON d3~tabname = d2~tabname
WHERE d3~fieldname = 'MATXT'
AND d2~tabclass = 'TRANSP'. << if you want to exclude structures
P.S. Your screenshot is almost unreadable.
Update:
SAP has plenty of modules and their consideration is out of the scope of your question.
Why they should? It is rhetorical question.
If you are nor ABAPer, you can simply use 'MATXT' as search predicate in SE11/SE16/SE16n for table DD03L.
F1 -> Technical Info command should help in finding used structures in most cases, but not in 100% of cases. To identify what tables are used in a transaction is almost impossible without such tools as Debugger, Traces and without ABAP experience.
I recently asked the following question and received a wonderful answer: SQL: Dynamic view with column names based on column values in source table
As someone not familiar at all with BusinessObjects, is there any way to perform this in InfoView? Would I have to edit the universe?
Sorry, I know this is a terrible question... but we're in a bind.
This might be possible via a derived table in the universe. A derived table allows you to write a custom query to provide objects in the universe.
I don't think so. It would require the dynamic creation and destruction of objects.
I'm new with Doctrine2 so my question can be easy to answer (I hope so).
First of all, here the SQL query that I'd want :
SELECT *
FROM Document
WHERE id NOT IN (SELECT document_id FROM Documents_Folders)
Pretty simple isn't it ? The porblem is that my table 'Documents_Folders' is not an entity. In fact, it was create because I have a many-to-many relation between my entities 'Document' and 'Folder'.
I tried several queries, but none worked.
Thanks.
It really does look pretty simple, so it's not the problem with your SQL.
So if you want some help, tell us what is the error that you get?
BTW Your database shouldn't care what you use Documents_Folders for - it's just a table. (I don't know Doctrine2, but it's still regular database underneath, isn't it?)
Out of curiosity, What is your business case here.
Are you trying to get orphaned documents?
A Document can be part of Many Folders and a Folder can have many Documents?
I am a little new to linq-to-sql. I was just thinking suppose you wanted a subset of fields (in your db table) to actually be a data model in your application, what do you do? What I have thought of so far is to create a view from the actual db table and build linq-able classes using it.
Or is there a better way of doing this?
try these Walkthrough: Creating LINQ to SQL Classes (O/R Designer)
or these implemented in MVC Creating Model Classes with LINQ to SQL
One option is you can create Anonymous Types and use it.