Trying to figure why NewID function stopped working on Oracle - sql

I have used SELECT NEWID() FROM DUAL to generate new (random) guids in the past.
However, today when tried I am getting the below Error:
ORA-00904: "NEWID": invalid identifier
I am not able to find this Particular Error by googling. So I guessed the case must be any of the two:
Either this has been somehow blocked by my System Admin or somehow the instance of Oracle is unable to find the Function due to some installation/ version update issues.
-or-
Oracle has stopped support for NEWID() and wants us to only use SYS_GUID() for Guid generation.
(if yes, then I'll have to implement a REGEXP_REPLACE as GUIDs in my system are '-' -separated.
Also - I'll have to update all existing codes that use NEWID()).
Any suggestion will be helpful. Thx.

Oracle has never had a built-in newID function. That is a function that exists in SQL Server so it is entirely possible that someone had previously created a custom newID function that you were accustomed to calling. Whether that function was just calling sys_guid under the covers or whether it was replicating the format of the GUIDs in SQL Server like this implementation is something you'd have to determine. Frequently, tools that help you migrate code from one database engine to another will install a library of functions that emulate the built-in functions of the source database engine in the target database in order to make migrations easier. So it is possible that the function you're accustomed to calling was installed by some migration tool.
Since you talk about "version/ installation issues" my guess is that you are connected to a new/ different database that doesn't have the function you are accustomed to. If so, you can probably just go to the previous database where the code worked and copy the code for the custom function to the new database. If you are connected to the same database with the same user where this previously worked, that would imply that someone has revoked your user's access to the function or dropped the function entirely in which case you'd need to talk to your DBA/ DevOps team to see what changed and why.

Related

WSO2 Identity Server - Adding Service Provider using SQL

WSO2 Identity Server 5.0.0
I am wondering what the full path of SQL queries would be if i wanted to create and update Service providers via SQL queries. It's more than adding to the SP_APP table as a newly inserted entry by that means doesn't show in the UI. I was looking through the identity-core code and got a little lost, since it seems to abstract out some intricate registry stuff.
Anyway, I'd love to know how I could navigate the database to look at stuff by these means.
I would suggest moving your WSO2 IS completely onto SQL Server. You can then see all the tables and scripts that are run against it (using something like QueryProfiler). To do this, follow the instructions: https://docs.wso2.com/display/ML111/Setting+up+Microsoft+SQL.
Note that at the end of the document you must run two scripts (not just the one they show):
<PRODUCT_HOME>/dbscripts/mssql.sql
<PRODUCT_HOME>/dbscripts/identity/mssql.sql
I have to admit that the documentation on WSO2 IS is not very good or complete, but they have been good at answering questions. SQL Server was hard to set up as some of the steps were old (as you see they reference SQL Server 2005), but if you know your way around SQL Server pretty well, you can figure out the minor things. The largest issue was the second .sql script that needed to be run.
That should set you up well enough to see what is being called when set up Service Providers, or anything else that goes into the database.

Adding support for REGEXP() in SQLite through Haskell HDBC?

I've unfortunately just realized that having committed to HDBC as a database access framework for connecting to my SQLite3 database, the ability to add a function to handle REGEXP() in SQLite SQL seems to exists only in Database.SQLite.
Regular expression is something I need in the application at SQL level, but before I start converting everything to Database.SQLite I just thought I'd ask whether there are other options...?
Ok,
I see that HDBC may not be able to provide this ability, but I found this extension for SQLite:
https://github.com/eatnumber1/sqlite-regexp
which will do just that via an SQL LOAD statement. Of course, this adds an external dependency, but it fixas the problem (without having to rewrite lots and lots of code).
EDIT:
Actually, it seems that I cannot use load_extension(X) inside of HDBC, which means that I cannot loda the extension. So this is still an open issue.

SQL Server 2012 keyword override

A question for which I already know there is no pretty answer.
I have a third party application that I cannot change. The application's database has been converted from MS Access to SQL Server 2012. The program connects with ODBC and does not care about the backend. It sends pretty straight-forward SQL that seems to work on SQL Server nicely as well.
There is however a problem with one table that has the name "PLAN" which I already know is a SQL Server keyword.
I know that you would normally access such a table with square brackets, but since I'm not able to change the SQL I was wondering if there is any "ugly" hack that can either override a keyword or transform SQL on the fly.
You could try to edit the third party application with a hex editor. If you find the strings PLAN, edit this to something like PPAN and then rename the table, views etc. If you catch all, it could work. But, of course it is an ugly thing.
I think you are screwed I am afraid. The only other approaches I could suggest are
Intercepting the network packets before it hits the SQL Server which is clearly quite complicated. See https://reverseengineering.stackexchange.com/questions/1617/server-side-query-interception-with-ms-sql-server and in particular answer https://reverseengineering.stackexchange.com/a/1816
Decompiling the program in order to change it if it's a Java or .Net app for instance.
I suspect you're hosed. You could
Wire up the 3rd party app to a shim MS Access database that uses linked tables, where the Access table is nothing but a pass-through to the underlying SQL Server table. What you want to do is:
Change the offending column names in the SQL Server schema.
Create the linked tables in Access
Create a set of view/query in access that has the same schema that the 3rd party app expects.
Having done that, the 3rd party app should be able to speak "Access SQL" like it always has. Access takes care of the "translation" to T-SQL. Life is good. I suspect you'll take something of a performance hit, since you're proxying everything through Access, but I don't think it'll be huge.
That would be my preferred solution.
The other option would be to write a "shim" DLL that implements the ODBC API and simply wraps the actual calls to the true ODBC driver. Then capture the requests and improve them as necessary prior to invoking the wrapped DLL method. The tricky part is that your 3rd party app might be going after columns by ordinal position or might be going after them by column name. Or a mix. That means that you might need to transform the columns names on the way back, which might be more difficult than it seems.

How to migrate shared database from Access to SQL Express

I have been using MS Access databases via DAO for many years, but feel that I ought to embrace newer techniques.
My main application runs on end user PCs (no server) and uses a shared database that is created and updated on-the-fly. When the application is first run it detects the absence of a database and creates a new empty one.
Any local user running the application is allowed to add or update records in this shared database. We have a couple of other shared databases, that contain templates, regional information, etc., but these are not updated directly by the application.
Updates of the application are released from time to time and each new update checks the main database version and if necessary executes code to bring the database up to the latest specification. This may involve the creation or deletion of tables and/or columns. New copies of the template databases are also included as part of the update.
Our users are not required to be computer-literate and should not need to run any sort of database management software beyond those facilities provided by the application.
It all works very nicely with DAO/Access, but I'm struggling to find how to do it with SQL Express. The databases seem to be squirrelled away in locations that are user-specific and database creation and update seems at best awkward to do by program code alone.
I came across some references "Xcopy deployment" that looks like it could be promising, but there seem to be references to "user instances" that sound suspiciously like something that's not shared. I'd appreciate advice from anyone who has done it.
It sounds to me like you haven't fully absorbed the fundamental difference between the Access Database Engine (ACE/Jet) and SQL Server:
When your users launch your Access application it connects to the Access Database Engine that has been installed on their machine. Their copy of ACE/Jet opens the shared database file (.accdb or .mdb) in the network folder. The various instances of ACE/Jet work together to manage concurrent updates, record locking, and so on. This is sometimes called a "peer-to-peer" or "shared-file" database architecture.
With an application that uses a SQL Server back-end, the copies of your application on each user's machine connect over the network to the same instance of SQL Server (that's why it's called "SQL Server"), and that instance of SQL Server manipulates the database (which is stored on its local hard drive) on behalf of all of the clients. This is called "client-server" or "server-based" database architecture.
Note that for a multi-user database you do not install SQL Server on the client machines, you only install the SQL Server Client components (OleDb and ODBC drivers). SQL Server itself is only installed in one place: the machine that will act as the SQL... Server.
re: "database creation and update seems at best awkward to do by program code alone" -- Not at all, it's just "different". Once again, you pass all of your commands to the SQL Server and it takes care of creating the actual database files. For example, once you've connected to the SQL Server if you tell it to
CREATE DATABASE NewDatabase
it will create the database files (NewDatabase.mdf and NewDatabase_log.LDF) in whatever local folder it uses to store such things, which is usually something like
C:\Program Files\Microsoft SQL Server\MSSQL10_50.SQLEXPRESS\MSSQL\DATA
on the server machine.
Note that your application never accesses those files directly. In fact it almost certainly cannot do so, and indeed your application does not even care where those files reside or what they are called. Your app simply talks to the SQL Server (e.g. ServerName\SQLEXPRESS) and the server takes care of the details.
Just to update on my progress. Inspired by suggestions here and this article on code project:
http://www.codeproject.com/Articles/63147/Handling-database-connections-more-easily,
I've created a wrapper for the ADO.NET methods that looks quite similar to the DAO stuff that I am familiar with.
I have a class that I can use just like a DAO Database. It wraps ADO methods like ExecuteReader, ExecuteNonQuery, etc. with overloads that can accept a SQL parameter. This allows me to directly replace DAO Recordsets with readers, OpenRecordset with ExecuteReader and Execute with ExecuteNonQuery.
Each method obtains and releases the connection from its parent class instance. These in turn open or close the underlying connection as required depending on the transaction state, if any. So a connection is held open for method calls that are part of a transaction, but closed immediately for a single call.
This has greatly simplified the migration of my program since much of the donkey work can be done by a simple "find and replace". The remaining issues are then relatively easy to find and sort out.
Thanks, once again to Gord and Maxwell for your advice.
This answer is too long to right down... but go to Microsoft page, there they explain how to make it: http://office.microsoft.com/en-us/access-help/move-access-data-to-a-sql-server-database-by-using-the-upsizing-wizard-HA010275537.aspx
I hope this help you!!

SQL Server - Checkout system for database objects?

I was wondering if anyone knows any 3rd party tools or existing functionality in SQL Server 2008 so that when someone is working on a table or procedure, it is locked out to that individual. I have searched the net extensively and can't seem to find anything relating to this. We are facing a problem where two people may be working on the same stored procedures and whoever executes last gets the code change! This kind of functionality would come in handy. I think that a lock or check in/check out system would be benefit a project, any ideas?
I am already hooked up to Redgate source control, which does not provide this functionality.
Thanks
Try and have a look at this SO discussion: How do I version my SQL Server database in SVN?
It might not lock things like you want, but it would help to ensure code is recoverable. You could also consider using DDL triggers as some kind of a checking mechanism.
you could try this: http://www.apexsql.com/sql_tools_version.aspx
Alternatively, try this: http://www.red-gate.com/products/sql-development/sql-source-control/entrypage/5-minutes?utm_source=google&utm_medium=cpc&utm_content=unmet_need&utm_campaign=sqlsourcecontrol&gclid=CK_qsPC5prUCFe7MtAodzC8ACA