Advantage Database server crash - crash

The following query makes an Advantage Database Server crash:
SELECT +SUM(0) FROM SYSTEM.IOTA
Note the + before SUM(0), this is the culprit.
If I replace + by -, no error occurs.
If I execute this query in local mode, this error pops up:
poQuery: Error 7200: AQE Error: State = S0000; NativeError = 2203;
[iAnywhere Solutions][Advantage SQL Engine]
An error was encountered while reading an intermediate or temporary file.
I discovered the problem while testing and, even if I agree there is no point to add a + before an aggregation instruction, it should not crash the server!
Thanks

It is confirmed to be a bug. The combination of the unary positive operator and the aggregate function is the cause of the problem. It will be fixed in a future update.

Related

plsql : New function inside an existing package compilation and syntax check

How do I compile a new function created inside a package in plsql, to see syntactical error and so on
You can't compile a single function - compile the whole package.
If your concern is about invalidating the whole package in case that function has errors, then
create a standalone function (i.e. outside of the package)
debug it
once it is OK (doesn't have syntax errors, returns result as expected), include it into the package
In addition to #Littefoot's advise I'd say: use a proper GUI. Oracle has a free tool called sql developer. It has a great interface for editing database objects (packages/functions/procedures/triggers). It highlights errors and is very well documented (https://www.thatjeffsmith.com/sql-developer/). Note that is does not point out syntax errors - but once you're a bit used to working with pl/sql they become obvious very quickly.
In Oracle, after compiling a procedure/function/package. If there is an error then the command will return with the message:
ORA-24344: success with compilation error
You can then use:
SHOW ERRORS
or
SELECT * FROM USER_ERRORS;
or, for example, for errors with packages in a specific schema:
SELECT *
FROM ALL_ERRORS
WHERE owner = 'SCHEMA_NAME'
AND type IN ( 'PACKAGE', 'PACKAGE BODY');
Which will list the errors (complete with line numbers and error messages) and you can then debug the procedure/function/package and recompile it.
fiddle

FreeTDS ODBC error "The identifier that starts with ... is too long. Maximum length is 128."

I've been using pyodbc and free TDS to a submit queries to a microsoft SQL-2012 without issue for a while now but have recently stumbled on an issue.
When I submit a longer query I get an error message saying that one of the identifiers is too long and the script crashes.
The EXACT same query works in management studio and doesn't even return a warning.
I've added the following to my code with no avail.
SET QUOTED_IDENTIFIER OFF
SET ANSI_NULLS ON
The piece of code that the error is referring to is here:
(ZR_KOPF.ZRK_DDP_B IN ('190/TEMP.AA1H', '190/RAIN.AA1H', '190/WDR.AA1H', '190/WSP.AA1H', '190/SD1.AA1H', '190/HUMID.AA1H', '190/NO2.AA1H', '190/PM10.AA1H', '190/PM2.5.AA1H', '190/SO2.AA1H', '190/OZONE.AA1H', '190/CO.AA1H', '206/TEMP.AA1H', '206/RAIN.AA1H', '206/WDR.AA1H', '206/WSP.AA1H', '206/SD1.AA1H', '206/HUMID.AA1H', '206/NO2.AA1H', '206/PM10.AA1H', '206/PM2.5.AA1H', '206/SO2.AA1H', '206/OZONE.AA1H', '206/CO.AA1H')) AND ZR_KOPF.ZRK_BASEPRODUCTION = 1)
The error I get is:
pyodbc.ProgrammingError: ('42000', "[42000] [FreeTDS][SQL Server]The identifier that starts with ''190/TEMP.AA1H', '190/RAIN.AA1H', '190/WDR.AA1H', '190/WSP.AA1H', '190/SD1.AA1H', '190/HUMID.AA1H', '190/NO2.AA1H', '190/PM10.AA' is too long. Maximum length is 128. (103) (SQLExecDirectW)")
Pyodbc version: 4.0.18b1
freetds version: 1.00.48
Any help would be much appreciated
Cheers!
So turns out the spaces between each of the items in the list made all the difference...
I removed them and the query worked without a hitch.
Thanks for all the help everyone!

[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='

I have started getting an error on a page and am really struggling to work out the cause of this. I have searched on Stack Overflow for this same error message and found some people that got it also, but there solutions were very different to mine. This is the error message I'm getting:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]Incorrect syntax near '='.
/test-page.asp, line 97
This related to this line on that .asp page:
set rsMainContact=oConn.execute
("SELECT * FROM tbl_individual WHERE individual_id="&iMainContact)
Now the strange thing about this is that the page is actually bringing up the correct data, it's getting all the data it needs from that table. Which is why I don't understand why there's a problem.
Also, when I run the query using the "SELECT * FROM tbl_individual WHERE individual_id="&iMainContact" statement in MSSQL, replacing &iMainContact for an actual variable, it works absolutely fine.
Does anyone have any idea why this error might be occurring?
In case you want to know where the various variables come from then this is also some relevant code from the page:
SET rsOrganisationPendingOrganic=Server.CreateObject("ADODB.RecordSet")
rsOrganisationPendingOrganic.CursorType=3
rsOrganisationPendingOrganic.Open sSQL, oConn
iOrganisationPendingOrganicCount=rsOrganisationPendingOrganic.RecordCount
iMainContact=rsOrganisationPendingOrganic("organisation_maincontact")
if the following code is run BEFORE the error occurs, you most likely have no value for iMainContact:
SET rsOrganisationPendingOrganic=Server.CreateObject("ADODB.RecordSet")
rsOrganisationPendingOrganic.CursorType=3
rsOrganisationPendingOrganic.Open sSQL, oConn
iOrganisationPendingOrganicCount=rsOrganisationPendingOrganic.RecordCount
iMainContact=rsOrganisationPendingOrganic("organisation_maincontact")
you can prove this by writing out the sql to the screen before executing the failing sql:
Response.Write "SELECT * FROM tbl_individual WHERE individual_id=" & iMainContact
Response.End
I also agree 1000% with lad2025, use parameterized queries to guard against sql injection

Why is my Deployment script causing me errors?

I am working on a project in visual studio 2012. Recently, I added a database project to the solution. The database already existed before I added it to the solution and everything worked fine.
Now, however, when I try to run the application I get errors. The errors are being caused by a computer-generated file called [database name].sql. At the top of the tile, it reads:
/*
Deployment script for [the database name here]
This code was generated by a tool.
Changes to this file may cause incorrect behavior and will be lost if
the code is regenerated.
*/
This file gets re-created every time the application runs. The errors that occur appear to be syntax errors. I cannot fix them because any changes I make to the file are irrelevant because a new file gets generated with each run and the errors re-appear.
I tried looking into this more online but had trouble. This is all rather new to me.
Here are some of the errors being created:
GO
:setvar DatabaseName "(the database name is here)"
which gives me three errors that read:
Error 88 SQL80001: Incorrect syntax near ':'.
Error 89 SQL80001: 'DatabaseName' is not a recognized option.
Error 90 SQL80001: Incorrect syntax near '"(the database name is here in the code)"'.
Also, there is a line of code that reads:
CREATE USER [(the domain)\(the username)] FOR LOGIN [(the domain)\(the username)];
GO
which gives the following error:
Error 119 SQL72014: .Net SqlClient Data Provider: Msg 15401, Level 16, State 1, Line 1 Windows NT user or group '(the domain)\(the username)' not found. Check the name again.
From the errors you have posted it looks like there are two issues:
Windows NT user or group '(the domain)\(the username)' not found. - The user being used to access the database doesn't exist. As it's a Windows user I'm guessing that it uses the current user's credentials.
Make sure that your instance of SQL can accept Windows logins and that you (and anyone else building the software) has the necessary access rights.
'DatabaseName' is not a recognized option. - This is more than likely also caused by the first issue, but double check that the database exists.
The error message caught me out recently as it did not relate to the cause of my problem at all. It turns out my SQL script was incorrectly written (for my case - I forgot to add IDENTITY (1,1) to my PK column) to begin with.
Moral of the story for me was to test out the SQL data file in SSMS first.

SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error or Access Violation

Good day!
I get this error:
SQL STATE 37000 [Microsoft][ODBC Microsoft Access Driver] Syntax Error
or Access Violation, when trying to run an embedded SQL statement on
Powerscript.
I am using MsSQL Server 2008 and PowerBuilder 10.5, the OS is Windows 7. I was able to determine one of the queries that is causing the problem:
SELECT top 1 CONVERT(DATETIME,:ls_datetime)
into :ldtme_datetime
from employee_information
USING SQLCA;
if SQLCA.SQLCODE = -1 then
Messagebox('SQL ERROR',SQLCA.SQLERRTEXT)
return -1
end if
I was able to come up with a solution to this by just using the datetime() function of PowerBuilder. But there are other parts of the program that is causing this and I am having a hard time in identifying which part of the program causes this. I find this very weird because I am running the same scripts here in my dev-pc with no problems at all, but when trying to run the program on my client's workstation I am getting this error. I haven't found any differences in the workstation and my dev-pc. I also tried following the instructions here, but the problem still occurs.
UPDATE: I was able to identify the other script that is causing the problem:
/////////////////////////////////////////////////////////////////////////////
// f_datediff
// Computes the time difference (in number of minutes) between adtme_datefrom and adtme_dateto
////////////////////////////
decimal ld_time_diff
SELECT top 1 DATEDIFF(MINUTE,:adtme_datefrom,:adtme_dateto)
into :ld_time_diff
FROM EMPLOYEE_INFORMATION
USING SQLCA;
if SQLCA.SQLCODE = -1 then
Messagebox('SQL ERROR',SQLCA.SQLERRTEXT)
return -1
end if
return ld_time_diff
Seems like passing datetime variables causes the error above. Other scripts are working fine.
Create a transaction user object inherited trom transaction.
Put logic in the sqlpreview of your object to capture and log the sql statement being sent to the db.
Instantiate it, connect to the db, and use it in your embedded sql.
Assuming the user gets the error you can then check what was being sent to the db and go from there.
The error in your first statement should be the second parameter to CONVERT function.
It's type is not a string, it's type is an valid expression
https://learn.microsoft.com/en-us/sql/t-sql/functions/cast-and-convert-transact-sql
So I would expect that your
CONVERT(DATETIME,:ls_datetime)
would evaluate to
CONVERT(DATETIME, 'ls_datetime')
but it should be
CONVERT(DATETIME, DateTimeColumn)
The error in your second statement could be that you're providing an wrong datetime format.
So please check if your error still occurs when you use this function
https://learn.microsoft.com/en-us/sql/t-sql/statements/set-dateformat-transact-sql
with the correct datetime format you're using