Weird OleDbDataAdapter Fill behavior (hangs with explicit fields) on IBM i System - db2

we're migrating our IBM i System from OS 6.0 to 7.4; we're testing all the applications which somehow connect and read/write data to it and we found a weird behavior in one of them.
The application is simply trying to fill a DataTable via OleDbDataAdapter:
Dim da As New OleDbDataAdapter
Dim dt As New DataTable
[...]
da.Fill(dt)
The query is a simple select similar to this:
SELECT field1, field2, field3 FROM table WHERE field1=something AND field2=something
.. and it returns 99% of the times (if not 100%) always an empty resultset (0 rows).
Problem is: the command da.Fill(dt) hangs for minutes most of the time with no specific reason or errors.
What's weird? If I replace the list of fields with *:
SELECT * FROM table WHERE field1=something AND field2=something
It works ALWAYS with no delays or glitches.
We really got no clues: could this be related to the new OS/400 version (7.4 instead of 6.0)? Maybe we need an updated ODBC driver (we're using a very old one)?
I cannot say where the command is hanging (ODBC side? IBM side? ...), but on IBM i System everything seems just to be in idle..
Thanks!
--
I did other tests changing the query a bit, and this are the results:
's = "Select SNORAF, SRIAFF, SCDREG, SCDPRV, SCDCOM, SCDTIP, SCDTIQ, SPSC01 from 'KO
's = "Select SNORAF, SRIAFF, SCDREG, SCDPRV, SCDCOM, SCDTIP, SPSC01, SCDTIQ from 'KO
's = "Select SNORAF, SRIAFF, SCDREG, SCDPRV, SCDCOM, SCDTIP, SCDTIQ, SPSC01, SCDTIQ from 'OK
's = "Select SNORAF, SRIAFF, SCDREG, SCDPRV, SCDCOM, SCDTIP, SCDTIQ, SCDTIQ, SCDTIQ from 'OK
's = "Select SNORAF, SRIAFF, SCDREG, SCDPRV, SCDCOM, SCDTIP, SPSC01 from 'OK
's = "Select * from 'OK
's = "Select SPSC01 'OK
On the right, the results: the first two queries didn't work, all the other ones work fine.

Related

See Oracle SQL Developer Procedure's Details in Dbeaver

I am new for using DBeaver. Can I see Oracle SQL Developer Procedure's Details in Dbeaver?
like this
enter image description here
Use the data dictionary.
You can get details of the object using:
SELECT *
FROM ALL_OBJECTS
WHERE object_name = 'PROCEDURE_NAME';
You can get further details on the procedure using:
SELECT *
FROM ALL_PROCEDURES
WHERE object_name = 'PROCEDURE_NAME';
You can get even more details on the compilation settings using:
SELECT *
FROM all_plsql_object_settings
WHERE name = 'PROCEDURE_NAME'
You can combine it all into one query:
SELECT o.owner,
o.object_name,
o.subobject_name,
o.object_id,
o.data_object_id,
o.object_type,
o.created,
o.last_ddl_time,
o.timestamp,
o.status,
o.temporary,
o.generated,
o.secondary,
o.namespace,
o.edition_name,
s.nls_length_semantics,
s.plsql_ccflags,
s.plsql_code_type,
s.plsql_debug,
s.plsql_optimize_level,
s.plsql_warnings
FROM all_objects o
LEFT OUTER JOIN all_plsql_object_settings s
ON (o.owner = s.owner AND o.object_name = s.name AND o.object_type = s.type)
WHERE o.object_name = 'PROCEDURE_NAME';
fiddle

Is it possible to add sql functions to an sql query?

I need to concatenate the result of a subquery in a file based model (i.e. with ms access) and following the suggestions I found here, I could define a function to use in the query.
I try that in the SQL scratch pad but nothing happens...
Function Coalsce(strSQL As String, strDelim, ParamArray NameList() As Variant)
Dim db As Database
Dim rs As DAO.Recordset
Dim strList As String
Set db = CurrentDb
If strSQL <> "" Then
Set rs = db.OpenRecordset(strSQL)
Do While Not rs.EOF
strList = strList & strDelim & rs.Fields(0)
rs.MoveNext
Loop
strList = Mid(strList, Len(strDelim))
Else
strList = Join(NameList, strDelim)
End If
Coalsce = strList
End Function
select switch(Coalsce(SELECT DISTINCT ', ' + obj_phase2.name as [text()]
FROM ((((t_object obj_ds2
INNER JOIN t_connector co2
ON (obj_ds2.object_id = co2.start_object_id))
INNER JOIN t_object obj_adu2
ON (co2.end_object_id = obj_adu2.object_id
AND obj_adu2.Stereotype='EUM_ADU'))
LEFT JOIN t_object obj_prx2
ON (obj_prx2.Classifier_guid = co2.ea_guid))
LEFT JOIN t_connector pc2
ON (obj_prx2.Object_ID = pc2.Start_Object_ID AND pc2.Stereotype = 'trace'))
LEFT JOIN t_object obj_phase2
ON (pc2.End_Object_ID = obj_phase2.object_id)
WHERE obj_ds2.Stereotype = 'EUM_Data-Stream' AND obj_ds2.Object_ID = 13919)='', '',
1=1, 'teste') as [test]
from t_object
Is this possible?
No. EA only allows SELECT statements in the scratchpad. EA is doing some black magic with the SQL before sending it to the database. Misty and obscure that is. But for sure you can not send VB code (or any other advanced stuff) through the pad.
If you want to get the above working you need to place the VB code in a script calling the SELECT via repository.SQLQuery.
It would probably be possible to run such stuff via a native ODBC or driver connection. However, I would absolutely not recommend doing that. I wouldn't do that myself and I've done a lot of strange things with EA.

Openerp create function doesn't execute query

Following is my create function for roster module. The problem is that only update query is not working. The query is working fine when it run alone in pgadmin but in here it doesn't. Both Select and Insert queries are working fine.
(I know using cr.execute is not a good practice but I am in little bit hurry with deadlines).
def create(self, cr, uid, values, context=None):
#rec_id=values['id']
sub_day=values['roster_day']
ros_time=values['time_slot']
emp = values['employee']
dept = values['department_id']
sub_emp = values['sub_employee']
#sub_day = datetime.datetime.strptime(sub_day, '%Y-%m-%d')
cr.execute("""SELECT ra.id , ra.emp_id FROM roster_allocation ra, roster_days_allocation rda
WHERE rda.roster_allocation_connection=ra.id and
rda.allocation_start_day='%s' and
rda.roster_time_list=%d and
ra.emp_id=%d"""%(sub_day,ros_time,emp))
exers=cr.fetchone()[0]
cr.execute("""INSERT INTO roster_allocation (write_uid,emp_id,department_id) VALUES(%d,%d,%d)""" %(context['uid'], sub_emp, dept))
print "Employee for substitution record inserted successfully"
cr.execute("""UPDATE roster_days_allocation SET roster_allocation_connection = (SELECT MAX(ra.id) FROM roster_allocation ra, roster_substitution rs
WHERE ra.emp_id=rs.sub_employee)
WHERE allocation_start_day = '%s' AND roster_time_list = %d AND roster_allocation_connection = %d""" %(sub_day, ros_time,exers))
print "Employee for substitution record updated successfully"
return super(roster_substitution, self).create(cr, uid, values, context=context)
I have edited UPDATE query and even though it's not the best practice, it worked.
cr.execute (SELECT MAX(ra.id) FROM roster_allocation ra, roster_substitution rs
WHERE ra.emp_id=rs.sub_employee)
val=cr.fetchone()
cr.execute("""UPDATE roster_days_allocation SET roster_allocation_connection = %d
WHERE allocation_start_day = '%s' AND roster_time_list = %d AND roster_allocation_connection = %d""" %(val,sub_day, ros_time,exers))

How to determine the size of a Full-Text Index on SQL Server 2008 R2?

I have a SQL 2008 R2 database with some tables on it having some of those tables a Full-Text Index defined. I'd like to know how to determine the size of the index of a specific table, in order to control and predict it's growth.
Is there a way of doing this?
The catalog view sys.fulltext_index_fragments keeps track of the size of each fragment, regardless of catalog, so you can take the SUM this way. This assumes the limitation of one full-text index per table is going to remain the case. The following query will get you the size of each full-text index in the database, again regardless of catalog, but you could use the WHERE clause if you only care about a specific table.
SELECT
[table] = OBJECT_SCHEMA_NAME(table_id) + '.' + OBJECT_NAME(table_id),
size_in_KB = CONVERT(DECIMAL(12,2), SUM(data_size/1024.0))
FROM sys.fulltext_index_fragments
-- WHERE table_id = OBJECT_ID('dbo.specific_table_name')
GROUP BY table_id;
Also note that if the count of fragments is high you might consider a reorganize.
If you are after a specific Catalogue
Use SSMS
- Clik on [Database] and expand the objects
- Click on [Storage]
- Right Click on {Specific Catalogue}
- Choose Propertie and click.
IN General TAB.. You will find the Catalogue Size = 'nn'
I use something similar to this (which will also calculate the size of XML-indexes, ... if present)
SELECT S.name,
SO.name,
SIT.internal_type_desc,
rows = CASE WHEN GROUPING(SIT.internal_type_desc) = 0 THEN SUM(SP.rows)
END,
TotalSpaceGB = SUM(SAU.total_pages) * 8 / 1048576.0,
UsedSpaceGB = SUM(SAU.used_pages) * 8 / 1048576.0,
UnusedSpaceGB = SUM(SAU.total_pages - SAU.used_pages) * 8 / 1048576.0,
TotalSpaceKB = SUM(SAU.total_pages) * 8,
UsedSpaceKB = SUM(SAU.used_pages) * 8,
UnusedSpaceKB = SUM(SAU.total_pages - SAU.used_pages) * 8
FROM sys.objects SO
INNER JOIN sys.schemas S ON S.schema_id = SO.schema_id
INNER JOIN sys.internal_tables SIT ON SIT.parent_object_id = SO.object_id
INNER JOIN sys.partitions SP ON SP.object_id = SIT.object_id
INNER JOIN sys.allocation_units SAU ON (SAU.type IN (1, 3)
AND SAU.container_id = SP.hobt_id)
OR (SAU.type = 2
AND SAU.container_id = SP.partition_id)
WHERE S.name = 'schema'
--AND SO.name IN ('TableName')
GROUP BY GROUPING SETS(
(S.name,
SO.name,
SIT.internal_type_desc),
(S.name, SO.name), (S.name), ())
ORDER BY S.name,
SO.name,
SIT.internal_type_desc;
This will generally give numbers higher than sys.fulltext_index_fragments, but when combined with the sys.partitions of the table, it will add up to the numbers returned from EXEC sys.sp_spaceused #objname = N'schema.TableName';.
Tested with SQL Server 2016, but documentation says it should be present since 2008.

How do I insert data into a Postgres table using PowerShell or VBScript?

I need to periodically query the event logs on a handful of servers and insert specific events into a Postgres table.
I am having trouble figuring out how I can insert data into a table via ODBC using PowerShell and/or VBScript. I'm reasonably familiar with both VBScript and PowerShell generally, and I can craft a SQL UPDATE statement that works, I'm just trying to tie the two together, which I've never done before.
I have the Postgres ODBC driver installed, I've configured a data source which tests OK.
Google isn't helping me thus far, can someone provide some pointers?
What part are you having trouble with? How far have you got? Do you have a connection open? Do you know the syntax of the connection string?
Prepare a connection:
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open dsn, dbuser, dbpass
insert:
insert = "insert into table (col1, col2) values (12, 'Example Record')"
conn.Execute insert
If conn.errors.Count > 0 Then
Dim counter
WScript.echo "Error during insert"
For counter = 0 To conn.errors.Count
WScript.echo "Error #" & DataConn.errors(counter).Number
WScript.echo " Description(" & DataConn.errors(counter).Description & ")"
Next
Else
WScript.echo "insert: ok"
End If
for completeness, query:
query = "select * from table where col1 = 7"
Set recordSet = conn.execute(query)
' result is an object of type ADODB.RecordSet
If you want powershell, try this post.
If you need to know the connection string, try connectionstrings.com.
Thanks for the response.
I used more Googling and eventually grokked enough ADO.NET to get it working, although it may not necessarily be "correct".
$DBConnectionString = "Driver={PostgreSQL UNICODE};Server=$DBIP;Port=$DBPort;Database=$DBName;Uid=$DBUser;Pwd=$DBPass;"
$DBConn = New-Object System.Data.Odbc.OdbcConnection
$DBConn.ConnectionString = $DBConnectionString
$DBCmd = $DBConn.CreateCommand()
[void]$DBCmd.Parameters.Add("#TimeStamp", [System.Data.Odbc.OdbcType]::varchar, 26)
[void]$DBCmd.Parameters.Add("#ErrorText", [System.Data.Odbc.OdbcType]::varchar, 4000)
$DBCmd.CommandText = "INSERT INTO errorinfo (errortime,xml) VALUES(?,?)"
$DBCmd.Connection.Open()
$DBCmd.Parameters["#TimeStamp"].Value = $TimeStamp.ToString("yyyy-MM-dd HH:mm:ss")
$DBCmd.Parameters["#ErrorText"].Value = $ErrorText
[void]$DBCmd.ExecuteNonQuery()