MSQL auditing with CLR integration - sql

I'm dot.net developer, and i'm working a lot with MSQL. My current task is when some user executes select query on database, i should "catch" the query data. What do i mean is if select query is "select * from UsersTbl where UserID = 5", i have to get '5'. Does somebody have any idea where to start???
Thanks a lot.
Dmitry

You could extract each value that starts with an =
But you might find a solution using MySQL Proxy... I've never used it so don't hold me to that :)

Related

Report that only displays employees directly reporting to the manager running the report

Hello I'm running Obi 11g and I'm creating a dashboard for managers and I'm having difficulty finding a way to create a report for the dashboard that shows only the employees directly reporting to the manager running the dashboard / report.
I've done a little research and I'm guessing this is going to be done by session variables? but i'm not sure how. If there was a way I can pull the executing user's username I could just say employee.username = session.username and then run the query accordingly but is there a way to this?
Any help would be appreciated greatly. Thanks.
This is Oracle. It offers a function named USER that returns ... well, current user. So, your query might utilize it as
where employee.username = user
Since this may be an Oracle product but not and Oracle database query, you will need sth more OBI-specific:
VALUEOF(NQ_SESSION.USER)
I found what I was looking for
SELECT fnd_global.user_name FROM DUAL
This posts the username instead of the schema.

Querying another DB while connecting to other Database in SQL

In my SQL script I am using one database(Lets assume MyDb1).
In side that script I need to query extended property of another DB (MyDb2).
I have no Idea to do this.
Please advise me.
You can use this Query :
SELECT * FROM MyDb1.DBO.TableName as tbl1,MyDb2.DBO.TableName as tbl2
WHERE tbl1.ID=tbl2.ID

SQL Query takes less than 1 sec in SSMS and forever in code

I'm running this query against a quite big table (i guess, around 150-200 000 rows):
select count(Distinct(eti.Email)) FROM table1 eti
LEFT OUTER JOIN table2 ti on ti.Email = eti.Email and ti.SiteId = eti.Site_Id
WHERE eti.Site_Id=1
In SMMS (SQL Server Management Studio) it takes less than 1 secound to execute but when I try to execute from my ASP.NET-site it times out.
I'm using PetaPoco to fetch the data which "under the hood" executes this code:
using (var cmd = CreateCommand(_sharedConnection, sql, args))
{
object val = cmd.ExecuteScalar();
OnExecutedCommand(cmd);
return (T)Convert.ChangeType(val, typeof(T));
}
I've been reading about that SSMS has som "special settings" when it executes the query? I really need to get this up and running.
Could the "MARS"-setting in the connection be have any impact on this? How do i debug and find the problem?
Thanks!
Thank you for the help!
I have finally found the issue (and it's a little embarrassing)... I found this blog question from msdn forums about sp_executesql being slow:
and Dan Guzman who is SQL Server MVP answers: http://social.msdn.microsoft.com/Forums/en-US/transactsql/thread/3cb08860-49a0-432a-8605-0af6b374dded/
Another possible issue is data type mismatches between the parameters and the column data types, resulting in non-sargable expressions and a bad plan. Please post your query and table DDL if you need further help.
So i doubled checked and it turned out that table2 had both the Email and the SiteId-fields set as "Nullable", changing them to match table1 fixed the issue.

How to Query Database Name in Oracle SQL Developer?

How do I query the database name in Oracle SQL Developer? I have tried the following and they all fail:
SELECT DB_NAME();
SELECT DATABASE();
Why do these basic MySQL queries fail in SQL Developer? Even this one fails too:
show tables;
EDIT: I can connect to the database and run queries such as:
select * from table_name_here;
EDIT 2: The database type is Oracle, this is why MySQL queries are failing. I thought it was related to the database client not the database itself. I was wrong. I'll leave the question as is for other as lost as I was.
Once I realized I was running an Oracle database, not MySQL, I found the answer
select * from v$database;
or
select ora_database_name from dual;
Try both. Credit and source goes to: http://www.perlmonks.org/?node_id=520376.
try this:
select * from global_name;
You can use the following command to know just the name of the database without the extra columns shown.
select name from v$database;
If you need any other information about the db then first know which are the columns names available using
describe v$database;
and select the columns that you want to see;
I know this is an old thread but you can also get some useful info from the V$INSTANCE view as well. the V$DATABASE displays info from the control file, the V$INSTANCE view displays state of the current instance.
Edit: Whoops, didn't check your question tags before answering.
Check that you can actually connect to DB (have the driver placed? tested the conn when creating it?).
If so, try runnung those queries with F5
To see database name,
startup;
then type
show parameter db_name;
DESCRIBE DATABASE NAME; you need to specify the name of the database and the results will include the data type of each attribute.

SQL query to get the source of a Stored Procedure

I'm using a DB2 database and I'm hoping for a query which will iterate over all stored procedures in a single database and print out the source code of each. No fancy formatting or performance requirements.
The reason for this (in case there's a better way of doing it) is I'm trying to track down usages of a particular table in our stored procs, so I want to be able to do a simple text search through all of them.
Also, I've got access to SQuirreL SQL client if anyone knows of a way via that.
Ah, figured it out. For other's reference:
select ROUTINENAME, TEXT from syscat.routines
where definer not in ('SYSIBM') AND ROUTINESCHEMA='databaseName'
I know this is old, but your answer started me on the right track. We are also using DB2, but don't have syscat.routines visible to us. However we do have SYSIBM.SYSROUTINES and that allows similar by doing
SELECT SCHEMA,
NAME,
TEXT
FROM SYSIBM.SYSROUTINES
WHERE SCHEMA = '<SCHEMA>'
and NAME = '<NAME>'
FOR FETCH ONLY WITH UR;