Subsonic 3 LeftOuterJoin - subsonic3

I have a problem. I want to create sql question
select * from Firma left outer join FirmaAdres on FirmaAdres.Typ = 1 and FirmaAdres.FirmaID = Firma.ID
in subsonic
I have written
SelectColumns("Firma.*").From().LeftOuterJoin(FirmaTable.IDColumn, FirmaAdresTable.FirmaIDColumn).And(FirmaAdresTable.AdresTypIDColumn).IsEqualTo(1)
When I checked what sql question is created I noticed then left outer join is changed to Inner join!!!
Could anyone help me??

Subsonic doesn't support LeftOuterJoin. You need to emulate the left join in LINQ (see http://www.devsource.com/c/a/Languages/Defining-a-Left-Join-with-LINQ-Queries/ for more details) In my opinion the effort don't deserves the pain that is wating for you. I suggest you to use a simple, boring and traditional stored procedure here.

Related

How to use Doctrine 2 DQL ON to override default JOIN condition

For starters, it is NOT a duplicate of Doctrine 2 JOIN ON error. I am indeed getting Expected end of string, got 'ON' but using WITH won't solve my case.
The problem there is similar but different from mine. I don't need to add a condition to my JOIN, I need to substitute the default condition with a different one.
Let's say, we have 2 hypthetical tables: album and artist, with an artist_id FK pointing from album to artist. In my case, I don't want to join artists with their albums. I want to list artists joined with unrelated albums using some arbitrary condition. So each artist will be joined with the exact same small set of albums. Believe me, in my case it does make sense - I don't want to describe it fully because it is too complex and out of the scope of my question.
SELECT * FROM artist
LEFT JOIN album ON album.some_unrelated_property = 'foo'
The example above is raw SQL (I'm using PostgreSQL) and works perfectly fine in this form.
In my code I'm using query builder (hard to avoid it, because my query is way more complex and built step by step by a series of functions). The line that causes an error is this:
$qb->leftJoin('artist.albums', 'aa', Join::ON, 'aa.someUnrelatedProperty = "foo"');
In Doctrine I'm getting the dreaded Expected end of string, got 'ON'. When I use WITH instead of ON it works, but as expected, it appends the standard join condition by artist_id which I do not want.
What's even more confusing for me, in this post: What is the difference between JOIN ON and JOIN WITH in Doctrine2? which explains a difference between ON and WITH in DQL, somebody uses an example equivalent to mine as a correct use of ON in DQL:
Case Two
DQL
FROM Album a LEFT JOIN a.Track t ON t.status = 1
Will translate in SQL
FROM Album a LEFT JOIN Track t ON t.status = 1
What am I missing here? Is it possible to achieve what I want at all, using DQL? If not, what the hell is the reason for ON to exist in DQL when there's also WITH which works in more standard cases?

Executing a "long-length" Oracle command in C++

Problem: I have a C++ application that executes different Oracle commands. My application can execute this SQL statement the following way (I have ommited error checking and a few earlier steps):
strcpy(szProcName,"select grantee, granted_role from DBA_ROLE_PRIVS;");
rc=SQLPrepare(sqlc.g_hstmt,(SQLCHAR*)szProcName,(SQLINTEGER)strlen(szProcName));
rc = SQLExecute(sqlc.g_hstmt);
The select statement's data is placed/binded into an MFC List Control. This works without problem...
The issue comes when I try to execute long-length select statements.
I now wish to use the same method, but to run this long SQL statement:
SELECT a.GRANTEE, a.granted_role as "Connect", b.granted_role as "APPUSER" FROM
(SELECT GRANTEE, granted_role from DBA_ROLE_PRIVS where GRANTED_ROLE = 'CONNECT') a
FULL OUTER JOIN
(SELECT GRANTEE, granted_role from DBA_ROLE_PRIVS where GRANTED_ROLE = 'APPUSER') b
ON a.GRANTEE=b.GRANTEE;
Setting that entire statement into szProcName seems like the wrong way to go about things.
What I have tried: I tried to add all the SQL text into szProcName, but it does not fit and makes the code terribly messy. I also thought to create a Stored Procedure to call in C++. The Stored Procedure requires that I use an INTO clause and does not produce a table that I can use in C++. Is there a better way to do this?
Edit: I have found one working way. By increasing szProcName's size and usingstrcat(), I can add each line and then execute. I still wonder if there is a more appropriate way, especially if my statements become any larger (which they probably will).
I have found one working way. By increasing szProcName's size and using strcat(), I can add each line and then execute. I still wonder if there is a more appropriate way, especially if my statements become any larger (which they have).

SQLite How to use LIKE on a column and add wild cards

I'm trying to compare 2 similar columns from 2 tables in SQLite. I wrote this which doesn't throw an error but also doesn't return anything and I know it should.
SELECT t1.* from t1, t2 Where t1.col1 Like '%'||t2.col1||'%';
I'm looking for when t2.col1 is embedded inside of t1.col1. Both columns are of type TEXT.
Note: I'm using the C-Interface in C++ with Visual Studio 2010.
Ideas?
Edit:
I've played around with pulling a value out of t2.col1 that matches something in t1.col1 and writing something like this,
SELECT t1.* from t1, t2 Where t1.col1 Like '%ValueInT1%';
which works and returns something.
Is there a bug with SQLite when concatenating the '%' character in a like statement or is there a different syntax I should be using? I'm at a loss for why this isn't working.
I've also seen an SQL function called Locate which people use in different Databases to do this kind of check. Does SQLite have a Locate function?
EDIT 2:
I've run the first SQL statement in SQLite Administrator with some of my data and it DOES find it. Could there be a simpler problem? There are '_' in the data could that be causing a problem with the like?
(V.V) The answer was that I was joining to the wrong column in the real table. 2 columns had very similar names and I was checking the wrong one.
Thanks for the help.

Updating two tables, retrieving Foreign Key

I am inserting data into two tables, however I can not figure out (after hours of Googling) how to insert data into the second table after retrieving the new ID created after the first update?
I'm using <CFINSERT>.
use <CFQUERY result="result_name"> and the new ID will be available at result_name.generatedkey .. <cfinsert> and <cfupdate>, while easy and fast for simple jobs, they are pretty limited.
I have never used cfinsert myself, but this blog post from Ben Forta says you may not be able to use cfinsert if you need a generated key http://www.forta.com/blog/index.cfm/2006/10/3/Use-CFINSERT-And-CFUPDATE
Yes, I realize that blog post is old, but it doesn't appear much has changed.
Why not use a traditional INSERT statement wrapped in a <cfquery> tag?

borland builder c++ oracle question

I have a Borland builder c++ 6 application calling Oracle 10g database. Operating over a LAN. When the application in question makes a simple db select e.g.
select table_name from element_tablenames where element_id = 10023842
the following is recorded as happening in Oracle (from the performance logs)
select table_name
from element_tablenames
where element_id = 10023842
then immediately (and not from C++ source code but perhaps deeper)
select table_name, element_tablenames.ROWID
from element_tablenames
where element_id = 10023842
The select statement is only called once in the TADODbQuery object, yet two queries are being performed - one to parse and the other adds the ROWID for executon.
Over a WAN and many, many queries this is obviously a problem to the user.
Does anyone know why this might be happening, can someone suggest a solution?
Agree with Robert.
The ROWID uniquely identifies a row in a table so that the returned record can be applied back to the database with any changes (or as a DELETE).
Is there a way to identify a particular column (or set of columns) as a primary key so that it can be used to identify a row without using a ROWID.
I don't know exactly where the RowID is coming from, it could be either the TAdoQuery implementation or the Oracle Driver. But I am sure I found the reason.
From the Oracle docs:
If the database table does not contain a primary key, the ROWID must be selected explicitly when populating DataTable.
So I suspect your Table does not have a primary key, either add one or add the rowid.
Either way this will solve the duplicate query problem.
Since you are concerned about performance. In general
Using TAdoQuery you can set the CursorType to optimize different behaviors for performance. This article covers this from a TAdoQuery perspective. MSDN also has an article that covers it from from a general ADO Perspective. Finally the specifications from the Oracle Driver can be useful.
I would recommend setting the Cursor to either as they are the only supported by Oracle
ctStatic - Bi-directional query produced.
ctOpenForwardOnly - Unidirectional query produced, fastest but can't call Prior
You can also play with CursorLocation to see how it effects your speed.