Unexpected EOF on client connection with an open transaction - postgresql

I want to using threading to connect postgresql
but postgresql log show:
unexpected EOF on client connection with an open transaction
here is my code:
conn = []
for i in range(10):
conn.append(psycopg2.connect("dbname=test user=higis password=dbrgdbrg host=10.1.1.215 port=5432"))
print conn
def test_query(a,b,c,d,name,i):
try:
#conn = psycopg2.connect("dbname=test user=higis password=dbrgdbrg host=10.1.1.215 port=5432")
cur = conn[i].cursor()
sql_query = "SELECT count(*) FROM " + str(name) + " WHERE ST_MAKEENVELOPE" + str(
(a, b, c, d, 4326)) + "&& wkb_geometry"
start = time.time()
cur.execute(sql_query)
#conn.commit()
end = time.time()
results_time = end - start
results = cur.fetchall()
cur.close()
conn[i].close()
#print results
#print results[0][0]
suit_f = open("/home/pj/Desktop/test/log/replicate_query_time.txt", 'a')
print >> suit_f, (
'range query table:,%s,(%s %s %s %s),%s,%s' % (name, a, b, c, d, results[0][0], results_time))
except Exception, e:
print e
a_all = [1,2,3,4,5,6,7,8,9,10]
b_all = [1,2,3,4,5,6,7,8,9,10]
c_all = [1,2,3,4,5,6,7,8,9,10]
d_all = [1,2,3,4,5,6,7,8,9,10]
threads = []
for i in range(10):
a = a_all[i]
b = b_all[i]
c = c_all[i]
d = d_all[i]
t = threading.Thread(target=test_query,args=(a,b,c,d,"replicate_table1",i))
threads.append(t)
if __name__ == '__main__':
i = 0
for t in threads:
print "Thread:" + str(i) + " t and the time = %s" %(ctime())
t.setDaemon(True)
t.start()
i = i+1
t.join()
#conn.commit()

At some point the server received a client connection which presented the appropriate credentials (and thus a session was established).
This log message is informing you that the client disconnected the session "it just walked away!" without shutting down cleanly. Maybe the code is throwing an exception before it gets to the cur.close() statement.

Related

Send data with sockets

I have 2 ESP8266 connected in wifi.
The client sends its local time
def heure():
annee = str(time.localtime()[0])
mois = str(time.localtime()[1])
jour = str(time.localtime()[2])
hours = str(time.localtime()[3])
mins = str(time.localtime()[4])
if int(mins) < 10:
mins = '0' + mins
timestr = annee + ':' + mois + ':' + jour +':' +hours + ':' + mins
return(timestr)
def emission(donnees):
adresse_serveur=socket.getaddrinfo("192.168.144.2",800)[0][-1]
com_net=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
com_net.connect(adresse_serveur)
com_net.send(donnees)
com_net.close()
timestr=heure()
donnees=str(timestr)
emission(donnees)
print (donnees) ---> 2023:2:1:18:08
On the server:
new_list=[]
conn, addr = s.accept()
reception_donnees=conn.recv(512)
for item in reception_donnees.split(b':'):
new_list.append(item.decode('ascii'))
conn.close()
print (new_list) ---> ['2000', '1', '1', '0', '00'] ???
I see that the client sends 2023 and the server shows 2000
Where is the error?
I searched the web but couldn't find anything

Is it possible to use an alternative to if/else statements in repl python 3.7?

Is there a better solution in python for making large strings of if/else statements for a random input using import random on version 3.7? I feel like it's a bit counterproductive to write the same if else statements for each input. If not, are there any ways to make my code more efficient?
if G.casefold() == "a":
Boss_Health = Boss_Health - A
print("user dealt", A, "damage with A")
print("Boss health:", Boss_Health)
print("Health:", Health)
print("Bosses turn")
print("")
G = random.randint(1, 20)
if G == 1:
Boss_L = Boss_L + Boss_A
print("Boss_L has been upgraded by", Boss_A, "and now deals",
Boss_L, "damage")
print("Boss Health:", Boss_Health)
print("Health:", Health)
print("users turn")
str(G)
G = input()
if G == 2:
Boss_Health = Boss_Health + Boss_B
print("Boss healed", Boss_B, "hp to Boss")
print("Boss Health:", Boss_Health)
print("Health:", Health)
print("users turn")
str(G)
G = input()
if G == 3:
Boss_M = Boss_M + Boss_B
print("Boss_M has been upgraded by", Boss_B, "and now deals",
Boss_M, "damage")
print("Boss Health:", Boss_Health)
print("Health:", Health)
print("users turn")
str(G)
G = input()
Usually, the first bit to look for is where there is duplication of code. In your program, I saw the following lines entered repeatedly:
print("Boss Health:", Boss_Health)
print("Health:", Health)
print("users turn")
str(G)
G = input()
Those would be a candidate to group into some type of function. Realizing that the value of "G" gets either a manual entry or a random entry, following is a version of your code with repeated code pulled out and placed into a separate function.
import random
def Vitals(b_h, h, rndm = None): # Separate function to handle repeated statements
print("Boss health:", b_h)
print("Health:", h)
print("Bosses turn")
print("")
z = " "
if rndm == "gen":
z = random.randint(1, 20)
else:
z = input("Enter your choice: ")
return z
def game_loop():
A = 1
G = " "
Boss_Health = 10
Boss_A = 2
Boss_B = 2
Boss_L = 1
Health = 20
while True:
if G.casefold() == "a":
Boss_Health = Boss_Health - A
print("user dealt", A, "damage with A")
G = Vitals(Boss_Health, Health, "gen")
if G == 1:
Boss_L = Boss_L + Boss_A
print("Boss_L has been upgraded by", Boss_A, "and now deals", Boss_L, "damage")
G = Vitals(Boss_Health, Health)
if G == 2:
Boss_Health = Boss_Health + Boss_B
print("Boss healed", Boss_B, "hp to Boss")
G = Vitals(Boss_Health, Health)
if G == 3:
Boss_M = Boss_M + Boss_B
print("Boss_M has been upgraded by", Boss_B, "and now deals", Boss_M, "damage")
G = Vitals(Boss_Health, Health)
if G == "q" or G == "Q":
break
G = Vitals(Boss_Health, Health)
return
game_loop()
Not having your full program, I improvised to create a user input loop to test this out. But the net effect is a shorter program that cuts down on repeated code which also reduces the chance of some inconsistencies creeping into the various blocks of code that utilize the function.
Give that a try.

Is this the correct behavior for SQL GET DIAGNOSTICS?

The documentation for the SQL statement GET DIAGNOSTICS indicates that you can request that diagnostic data be placed in specific variables, with the relevant variable names and types listed. The articles here and here show how one can use this SQL statement in the context of an RPG program.
It looks like some of the results that I am getting back from DB2 do not match what the documentation and articles say. I am on IBM i, version 7.3.
I am looking at the diagnostic data that is being returned from a SQL user-defined table function (UDTF). If you use the clause "ALL" you can get a string that contains all the values:
COMMAND_FUNCTION=FETCH;
COMMAND_FUNCTION_CODE=+45;
DB2_NUMBER_CONNECTIONS=+1;
MORE=N;
NUMBER=+1;
CONDITION_NUMBER=+1;
DB2_MESSAGE_ID=SQL0443;
DB2_MESSAGE_ID1=CPF503E;
DB2_MODULE_DETECTING_ERROR=QSQFETCH;
DB2_ORDINAL_TOKEN_1=*N.*N;
DB2_ORDINAL_TOKEN_2=DUMMYUDTF;
DB2_ORDINAL_TOKEN_3=*******.DUMMYUDTF;
DB2_ORDINAL_TOKEN_4=Parameter '2' cannot be null.;
DB2_RETURNED_SQLCODE=-443;
DB2_TOKEN_COUNT=+4;
DB2_TOKEN_STRING=*N.*NDUMMYUDTFDUMMYUDTFParameter '2' cannot be null.;
MESSAGE_LENGTH=Parameter '2' cannot be null.;
MESSAGE_OCTET_LENGTH=Parameter '2' cannot be null.;
MESSAGE_TEXT=Parameter '2' cannot be null.;
RETURNED_SQLSTATE=90002;
ROUTINE_NAME=DUMMYUDTF;
ROUTINE_SCHEMA=QGPL;
SERVER_NAME=******;
SPECIFIC_NAME=DUMMYUDTF;
DB2_SQLERRD_SET=Y;
DB2_SQLERRD1=-168758331;
CONNECTION_NAME=******;
DB2_AUTHORIZATION_ID=********;
DB2_CONNECTION_METHOD=D;
DB2_CONNECTION_NUMBER=+1;
DB2_CONNECTION_STATE=+1;
DB2_CONNECTION_TYPE=+1;
DB2_PRODUCT_ID=QSQ07030;
DB2_SERVER_CLASS_NAME=DB2 for i;
DB2_SERVER_NAME=******;
The documentation states that fields MESSAGE_LENGTH and MESSAGE_OCTET_LENGTH should be integers. As you can see they are both VARCHARs. If I write code that defines these variables as integers, I get escape message: Scalar operand does not have attributes required by instruction. in the job log and two diagnostic, severity 50 SQL system error. along with a SQL service dump QSQSVCDMP. Another anomoly is that variable DB2_MESSAGE_ID2 does not look like it is implemented and can make the program crash on the line where SQL assigns it.
In contrast, if I use GET DIAGNOSTICS on a built-in function, the data types all match what the documentation says and all the variables seem like they are available:
COMMAND_FUNCTION=SELECT;
COMMAND_FUNCTION_CODE=+65;
DB2_NUMBER_CONNECTIONS=+1;
MORE=N;
NUMBER=+1;
CLASS_ORIGIN=ISO9075;
CONDITION_NUMBER=+1;
DB2_MESSAGE_ID=SQL0138;
DB2_MESSAGE_ID1=CPF4278;
DB2_MESSAGE_ID2=CPD4317;
DB2_MODULE_DETECTING_ERROR=QSQOPEN;
DB2_ORDINAL_TOKEN_1=*N;
DB2_RETURNED_SQLCODE=-138;
DB2_TOKEN_COUNT=+1;
DB2_TOKEN_STRING=*N;
MESSAGE_LENGTH=+47;
MESSAGE_OCTET_LENGTH=+47;
MESSAGE_TEXT=Argument *N of substringing function not valid.;
RETURNED_SQLSTATE=22011;
ROUTINE_CATALOG=******;
SERVER_NAME=******;
SUBCLASS_ORIGIN=ISO9075;
DB2_SQLERRD_SET=Y;
DB2_SQLERRD1=-185403400;
DB2_SQLERRD2=-185339401;
CONNECTION_NAME=******;
DB2_AUTHORIZATION_ID=********;
DB2_CONNECTION_METHOD=D;
DB2_CONNECTION_NUMBER=+1;
DB2_CONNECTION_STATE=+1;
DB2_CONNECTION_TYPE=+1;
DB2_PRODUCT_ID=QSQ07030;
DB2_SERVER_CLASS_NAME=DB2 for i;
DB2_SERVER_NAME=******;
Is this a bug that should be reported to IBM? How does one go about doing that? I have made a UDTF and a calling RPGLE program to demonstrate the problem. That code is below if anyone wants to verify my findings. You will probably have to comment out a few lines in RPGLE program TSTDIAUDTF because you do not have my error message service program ERRFUNC.
DUMMYUDTF is an external user-defined SQL function with code in SQL and in RPGLE. TSTDIAUDTF is an RPGLE program that I am using to test the behavior of the GET DIAGNOSTICS SQL statement.
This seems broadly similar to some bugs reported in the past, for instance SI44066, but the details are different.
Edit:
Corrected code formatting errors from earlier botched paste operation.
DUMMYUDTF, TXT
-- Build function by calling:
-- RUNSQLSTM SRCFILE(*******/QTXTSRC) SRCMBR(DUMMYUDTF) COMMIT(*NONE)
CREATE OR REPLACE FUNCTION DummyUDTF(
parm1 NUMERIC(7,0),
parm2 VARCHAR(7)
parm3 VARCHAR(4))
RETURNS TABLE (Out1 NUMERIC(7,0),
Out2 VARCHAR(13),
Out3 VARCHAR(4),
Out4 NUMERIC(7,2),
Out5 NUMERIC(5,4))
LANGUAGE RPGLE
DETERMINISTIC
READS SQL DATA
CALLED ON NULL INPUT
DISALLOW PARALLEL
NOT FENCED
EXTERNAL NAME '******/DUMMYUDTF'
PARAMETER STYLE DB2SQL;
DUMMYUDTF, SQLRPGLE
/IF DEFINED (*CRTBNDRPG)
H DFTACTGRP(*NO) ACTGRP('DUMMYUDTF')
/ENDIF
H DEBUG
H ALWNULL(*USRCTL) OPTION(*NoDebugIO) EXTBININT(*YES)
D DUMMYUDTF PI
* Input Parameters
D parm1 7S 0
D parm2 7A VARYING
D parm3 4A VARYING
* Columns to be returned
D out1 7S 0
D out2 13A VARYING
D out3 4A VARYING
D out4 7S 2
D out5 5S 4
* NULL Indicators for all input and output parameters
D parm1_n 5I 0
D parm2_n 5I 0
D parm3_n 5I 0
D out1_n 5I 0
D out2_n 5I 0
D out3_n 5I 0
D out4_n 5I 0
D out5_n 5I 0
* SQL Function Parameters
D OutputSQLState 5A
D FunctionName 517A VARYING CONST
D SpecificName 128A VARYING CONST
D MessageText 1000A VARYING
D CallType 10I 0
* Locals
D CallTypeFirst C CONST(-2)
D CallTypeOpen C CONST(-1)
D CallTypeFetch C CONST(0)
D CallTypeClose C CONST(1)
D CallTypeFinal C CONST(2)
D out DS TEMPLATE QUALIFIED
D out1 7S 0
D out2 13A VARYING
D out3 4A VARYING
D out4 7S 2
D out5 5S 4
D results DS DIM(99) LIKEDS(out)
D index S 2S 0
D count S 2S 0
D var4 S 7S 2
D var5 S 5S 4
MONITOR;
OutputSQLState = *ZEROS; // Initialize Output Parameters
CLEAR MessageText;
SELECT;
WHEN CallType = CallTypeOpen;
IF parm1_n = -1;
MessageText = BuildNullError('1');
RETURN;
ENDIF;
IF parm2_n = -1;
MessageText = BuildNullError('2');
RETURN;
ENDIF;
IF parm3_n = -1;
MessageText = BuildNullError('3');
RETURN;
ENDIF;
IF parm1 < 1;
OutputSQLState = '90002';
MessageText = 'Parameter 1 must be a number greater than 0.';
RETURN;
ENDIF;
EXSR BuildDummyData;
WHEN CallType = CallTypeFetch;
index += 1;
IF index > count;
OutputSQLState = '02000';
RETURN;
ENDIF;
out1 = results(index).out1;
out2 = results(index).out2;
out3 = results(index).out3;
out4 = results(index).out4;
out5 = results(index).out5;
WHEN CallType = CallTypeClose;
*INLR = *ON;
ENDSL;
ON-ERROR;
DUMP; // This dump ends up in the output queue QUSRSYS\QEZDEBUG
OutputSQLState = '90001';
MessageText = 'Error occurred in RPG program ''DUMMYUDTF''. ' +
'See program dump for additional details.';
ENDMON;
RETURN;
********************************************************************
BEGSR BuildDummyData;
EXEC SQL SELECT 350.05, .65
INTO :var4, :var5
FROM SYSIBM.SYSDUMMY1;
SaveToResults(parm1 : parm2 : parm3 : var4 : var5);
SaveToResults(219 : 'ABCDEF' : 'ZYXW' : 20.1 : .65);
SaveToResults(438 : 'GHIJKLMNOP' : 'ZYXW' : 2.95 : 0);
ENDSR;
********************************************************************
P BuildNullError...
P B
D PI 1000A VARYING
D parmName 20A VALUE VARYING
OutputSQLState = '90002';
RETURN 'Parameter ''' + parmName + ''' cannot be null.';
P E
********************************************************************
P SaveToResults...
P B
D PI
D loc1 7S 0 VALUE
D loc2 13A VALUE VARYING
D loc3 4A VALUE VARYING
D loc4 7S 2 VALUE
D loc5 5S 4 VALUE
IF count = 99;
OutputSQLState = '10Z01';
MessageText = 'SQL warning in DUMMYUDTF +
More than 99 parts generated.';
ELSE;
count += 1;
results(count).out1 = loc1;
results(count).out2 = loc2;
results(count).out3 = loc3;
results(count).out4 = loc4;
results(count).out5 = loc5;
ENDIF;
P E
TSTDIAUDTF, SQLRPGLE
H DEBUG(*YES)
H MAIN(Main)
H DFTACTGRP(*NO)
H BNDDIR('ERRFUNC')
/copy QRPGLESRC,ERRFUNCPR
D Message DS LIKEDS(ErrorMsg)
D success S 3I 0
D failure S 3I 0
D diagAll S 32740A VARYING
D displayText S 52A
D dummyItem DS INZ
D out1 7S 0
D out2 13A
D out3 4A
D out4 7S 2
D out5 5S 4
D SQLDiagData DS INZ
D MessageID 10A
D MessageID1 7A
D MessageID2 7A
D MessageLength 5I 0
D MessageText 32740A VARYING
D otherType 32740A VARYING
D ReturnedSQLCode...
D 5A
D ReturnedSQLState...
D 5A
D RowCount 10I 0
P Main B
DSPLY 'Beginning of test';
TestDummyUDTF();
TestDiagnoticsFromUDTF();
TestDiagnoticsFromBIF();
DSPLY ('Successful tests: ' + %char(success));
DSPLY ('Failed tests: ' + %char(failure));
RETURN;
BEGSR *PSSR;
DUMP;
DSPLY 'Unexpected error while running tests.';
GetErrorMsg(Message);
DSPLY ('Message.MsgId: ' + Message.MsgId);
DSPLY (%subst(Message.MsgText:1:52));
RETURN;
ENDSR;
P E
********************************************************************
P TestDiagnoticsFromBIF...
P B
D text S 10A
DSPLY 'Causing error from SUBSTR to read diagnostics.';
EXEC SQL SELECT SUBSTR('ABC', 1, -1) INTO :text
FROM SYSIBM.SYSDUMMY1;
IF SQLSTATE = '00000';
failure +=1;
DSPLY 'Test failed. Data returned, no error.';
ELSEIF SQLSTATE = '02000';
failure +=1;
DSPLY 'Test failed. No error returned.';
ELSE;
ReadSQLDiagnosticsAll();
IF diagAll <> '';
success += 1;
DisplayTextWindow(diagAll : 'CPF9898':'QCPFMSG');
DSPLY 'GET DIAGNOSTICS ALL succeeded.';
ELSE;
failure +=1;
DSPLY 'GET DIAGNOSTICS ALL failed.';
ENDIF;
ReadSQLDiagnosticsAllCondition();
IF diagAll <> '';
success += 1;
DisplayTextWindow(diagAll : 'CPF9898':'QCPFMSG');
DSPLY 'GET DIAGNOSTICS ALL CONDITION succeeded.';
ELSE;
failure +=1;
DSPLY 'GET DIAGNOSTICS ALL CONDITION failed.';
ENDIF;
ReadSQLDiagnostics();
IF ReturnedSQLCode <> '-138 ' OR
ReturnedSQLState <> '22011';
failure +=1;
DSPLY 'Test failed. Unexpected diagnostic.';
displayText = 'SQLCODE ' + ReturnedSQLCode +
' SQLSTATE ' + ReturnedSQLState;
DSPLY displayText;
ELSE;
displayText = MessageText;
DSPLY displayText;
displayText = 'MESSAGE_LENGTH ' + %char(MessageLength);
DSPLY displayText;
displayText = 'DB2_MESSAGE_ID ' + MessageID +
' DB2_MESSAGE_ID1 ' + MessageID1;
DSPLY displayText;
displayText = 'DB2_MESSAGE_ID2 ' + MessageID2;
DSPLY displayText;
IF MessageText <> '';
success += 1;
DSPLY 'GET DIAGNOSTICS MessageText succeeded.';
ELSE;
failure +=1;
DSPLY 'GET DIAGNOSTICS MessageText failed.';
ENDIF;
ENDIF;
ENDIF;
P E
********************************************************************
P TestDiagnoticsFromUDTF...
P B
D var2 S 7A
D var2_n S 5I 0
var2_n = -1;
DSPLY 'Causing error from DummyUDTF to read diagnostics.';
EXEC SQL DECLARE CUR_DIAG_UDTF CURSOR FOR (
SELECT ITEMS.*
FROM TABLE (QGPL.DummyUDTF(22, :var2 :var2_n, 'ZZ')) AS ITEMS
);
EXEC SQL OPEN CUR_DIAG_UDTF;
DOW 1=1;
EXEC SQL FETCH CUR_DIAG_UDTF INTO :dummyItem;
IF SQLSTATE = '00000';
failure +=1;
DSPLY 'Test failed. Records returned, no error.';
LEAVE;
ELSEIF SQLSTATE = '02000';
failure +=1;
DSPLY 'Test failed. No error returned.';
LEAVE;
ELSE;
ReadSQLDiagnosticsAll();
IF diagAll <> '';
success += 1;
DisplayTextWindow(diagAll : 'CPF9898':'QCPFMSG');
DSPLY 'GET DIAGNOSTICS ALL succeeded.';
ELSE;
failure +=1;
DSPLY 'GET DIAGNOSTICS ALL failed.';
ENDIF;
ReadSQLDiagnosticsAllCondition();
IF diagAll <> '';
success += 1;
DisplayTextWindow(diagAll : 'CPF9898':'QCPFMSG');
DSPLY 'GET DIAGNOSTICS ALL CONDITION succeeded.';
ELSE;
failure +=1;
DSPLY 'GET DIAGNOSTICS ALL CONDITION failed.';
ENDIF;
ReadSQLDiagnosticsUDTF();
IF ReturnedSQLCode <> '-443 ' OR
ReturnedSQLState <> '90002';
failure +=1;
DSPLY 'Test failed. Unexpected diagnostic.';
displayText = 'SQLCODE ' + ReturnedSQLCode +
' SQLSTATE ' + ReturnedSQLState;
DSPLY displayText;
ELSE;
* DSPLY MessageID;
* DSPLY %char(MessageLength);
displayText = MessageText;
DSPLY displayText;
displayText = 'MESSAGE_LENGTH ' + OtherType;
DSPLY displayText;
displayText = 'DB2_MESSAGE_ID ' + MessageID +
' DB2_MESSAGE_ID1 ' + MessageID1;
DSPLY displayText;
IF MessageText <> '';
success += 1;
DSPLY 'GET DIAGNOSTICS MessageText succeeded.';
ELSE;
failure +=1;
DSPLY 'GET DIAGNOSTICS MessageText failed.';
ENDIF;
ENDIF;
LEAVE;
ENDIF;
ENDDO;
EXEC SQL CLOSE CUR_DIAG_UDTF;
P E
********************************************************************
P TestDummyUDTF...
P B
D expected DS DIM(3) LIKEDS(dummyItem)
D index S 3I 0
expected(1).out1 = 22;
expected(1).out2 = 'AAAA';
expected(1).out3 = 'ZZ';
expected(1).out4 = 350.05;
expected(1).out5 = .65;
expected(2).out1 = 219;
expected(2).out2 = 'ABCDEF';
expected(2).out3 = 'ZYXW';
expected(2).out4 = 20.1;
expected(2).out5 = .65;
expected(3).out1 = 438;
expected(3).out2 = 'GHIJKLMNOP';
expected(3).out3 = 'ZYXW';
expected(3).out4 = 2.95;
expected(3).out5 = 0;
DSPLY 'Running test on DummyUDTF, success expected.';
EXEC SQL DECLARE CUR_UDTF CURSOR FOR (
SELECT ITEMS.*
FROM TABLE (QGPL.DummyUDTF(22, 'AAAA', 'ZZ')) AS ITEMS
);
EXEC SQL OPEN CUR_UDTF;
DOW 1=1;
EXEC SQL FETCH CUR_UDTF INTO :dummyItem;
IF SQLSTATE = '00000';
index += 1;
IF out1 <> expected(index).out1 OR
out2 <> expected(index).out2 OR
out3 <> expected(index).out3 OR
out4 <> expected(index).out4 OR
out5 <> expected(index).out5;
failure +=1;
DSPLY 'Test failed. Data mismatch from UDTF.';
ELSE;
success += 1;
DSPLY 'Test succeeded.';
ENDIF;
LEAVE;
ELSEIF SQLSTATE = '02000';
IF index = 0;
failure +=1;
DSPLY 'Test failed. No records returned.';
ENDIF;
LEAVE;
ELSE;
failure +=1;
DSPLY ('Test failed. SQLSTATE ' + SQLSTATE);
// ReadSQLDiagnostics();
LEAVE;
ENDIF;
ENDDO;
EXEC SQL CLOSE CUR_UDTF;
RETURN;
P E
**************************************************************************
P ReadSQLDiagnostics...
P B
D PI
D condition# 5I 0 VALUE OPTIONS(*NOPASS)
IF %parms = 0 OR condition# < 1;
condition# = 1;
ENDIF;
EXEC SQL GET DIAGNOSTICS CONDITION :condition#
:SQLDiagData.ReturnedSQLCode = DB2_RETURNED_SQLCODE,
:SQLDiagData.ReturnedSQLState = RETURNED_SQLSTATE,
:SQLDiagData.MessageText = MESSAGE_TEXT,
:SQLDiagData.MessageLength = MESSAGE_LENGTH,
:SQLDiagData.MessageID = DB2_MESSAGE_ID,
:SQLDiagData.MessageID1 = DB2_MESSAGE_ID1,
:SQLDiagData.MessageID2 = DB2_MESSAGE_ID2;
RETURN;
P E
**************************************************************************
P ReadSQLDiagnosticsUDTF...
P B
D PI
D condition# 5I 0 VALUE OPTIONS(*NOPASS)
IF %parms = 0 OR condition# < 1;
condition# = 1;
ENDIF;
EXEC SQL GET DIAGNOSTICS CONDITION :condition#
:SQLDiagData.ReturnedSQLCode = DB2_RETURNED_SQLCODE,
:SQLDiagData.ReturnedSQLState = RETURNED_SQLSTATE,
:SQLDiagData.MessageText = MESSAGE_TEXT,
:SQLDiagData.otherType = MESSAGE_LENGTH,
:SQLDiagData.MessageID = DB2_MESSAGE_ID,
:SQLDiagData.MessageID1 = DB2_MESSAGE_ID1;
// :SQLDiagData.MessageLength = MESSAGE_LENGTH,
// :SQLDiagData.MessageID = DB2_MESSAGE_ID;
RETURN;
P E
************************4*************************************************
P ReadSQLDiagnosticsAll...
P B
EXEC SQL GET DIAGNOSTICS :diagAll = ALL;
RETURN;
P E
**************************************************************************
P ReadSQLDiagnosticsAllCondition...
P B
D PI
D condition# 5I 0 VALUE OPTIONS(*NOPASS)
IF %parms = 0 OR condition# < 1;
condition# = 1;
ENDIF;
EXEC SQL GET DIAGNOSTICS :diagAll = ALL CONDITION;
RETURN;
P E
P DisplayTextWindow...
P B Export
D PI
D Text 8192 Const Varying
D MessageId 7 Const
D MessageFile 21 Const
D ErrCode DS
D BytesIn 10I 0 INZ(0)
D BytesOut 10I 0 INZ(0)
DQUILNGTX PR EXTPGM('QUILNGTX')
D MsgText 8192 CONST
D MsgLength 10I 0 CONST
D MessageId 7 CONST
D MessageFile 21 CONST
D dsErrCode LIKE(ErrCode)
QUILNGTX(Text : %Len(Text) :
MessageId : MessageFile : ErrCode);
P E
Yeah, it looks like it could be a bug...or given the PTF you linked to...it could be a limitation of GET DIAGNOSTICS when working with external UDTFs.
I see the same thing on 7.2.
What PTF level's are you at? If not current, IBM will ask you to get current.
You can report the issue here: https://www-946.ibm.com/support/servicerequest/Home.action
IBM will likely ask for code to reproduce. You'll probably want to cut down your example to the bare minimum to reproduce. Actually, it's s good idea to do so beofre posting to stackoverflow the next time.
As an example, here's all that's needed when calling the UDTF to see the problem:
**free
ctl-opt actgrp(*NEW) main(mainline) cvtopt(*NOVARCHAR) debug(*yes);
dcl-pr mainline extpgm('TESTRPGLE');
end-pr;
dcl-proc mainline;
dcl-s diagAll varchar(32740);
dcl-ds dummyItem qualified;
out1 zoned(7);
out2 varchar(13);
out3 varchar(4);
out4 zoned(7:2);
out5 zoned(5:4);
end-ds;
dcl-s nullArr int(5) dim(5);
exec sql
declare C1 cursor for (
SELECT ITEMS.*
FROM TABLE (DummyUDTF(22, cast(null as varchar(7)), 'ZZ')) AS ITEMS
);
exec sql
open C1;
//I expected SQLSTATE to be 90002 here, but it's not
if sqlstate <> *ZEROS;
exec sql
get diagnostics :diagAll = ALL;
dump;
return;
endif;
exec sql
fetch C1 into :dummyItem :nullArr;
//here's where the SQLSTATE of 90002 is returned.
if sqlstate <> *ZEROS;
exec sql
get diagnostics :diagAll = ALL;
dump;
return;
endif;
return;
end-proc;
side note: start using fully free format ;)

Only one process worked when using the multiprocess of Mongodb to scan one 2T collection,

my code:
import pymongo
import multiprocessing
import sys
import time
import re
def process_document(document):
xxxx
def process_cursor(processid,start,count_per_process):
print "process id is %d starting" % (processid)
cli = pymongo.MongoClient(host=["xxx:27017", "xxx:27017"], replicaSet='xxxx', readPreference="secondary")
table = cli['tydata']['users']
docs = table.find().skip(start).limit(count_per_process)
print "process id is %d processing" % (processid)
final_chip = 0L
total=0
count=0
if docs:
for doc in docs:
final_chip += process_document(doc)
count += 1
total+=1
if count == 1000000:
print 'counting is %d,time %d,processid %d' % (count,time.time(),processid)
print 'now is %d,processid %d' % (total, processid)
count = 0
print 'total is %d'%total
print "process id is %d ending" %(processid)
queue.put(final_chip)
if __name__ == "__main__":
total=282039860
process_num = 10
count_per_process = total / process_num
queue=multiprocessing.Queue()
process_list = []
start_time=time.time()
print start_time
for id in range(process_num):
start=id*count_per_process
p = multiprocessing.Process(target=process_cursor,args=(id,start,count_per_process,))
process_list.append(p)
for i in range(process_num):
process_list[i].start()
for i in range(process_num):
process_list[i].join()
end_time=time.time()
print end_time
while not queue.empty():
a = queue.get()
sum += a
print 'sum is %d'%sum
file_name= '/home/xxx/test_mongodb/script_mongodb/sum.txt'
file=open(file_name,'w')
file.write(str(sum))
file.flush()
file.close()
print 'the process total time is %d'%(end_time-start_time)
I used the multiprocess of Mongodb to scan one 2T collection, pymongo, but only one process worked, the others waited. I do not why only one process worked, and the others wait at the end, then another one works.
Is anything wrong with my code?

Getting error from: dlen = uint32(0) ;

I don't know why but I am getting this error:
Error in mr_lsbpex (line 3)
dlen = uint32(0) ;
Output argument "a" (and maybe others) not assigned during call to "E:\path\mr_lsbpex.m>mr_lsbpex"
I have tested "dlen = uint32(0) ;" in matlab enviorment (outside of this function) and everything was OK. Here is my code:
function a = mr_lsbpex ( r, p )
% extract from an array
dlen = uint32(0) ;
s = size (r) ;
rnd = rand (s(1),s(2)) ;
rd = 32 ;
rl = s(2) ;
for i=1:s(2)
if rnd(1,i)<rd/rl
d = bitget (round(r(1,i)/p),1);
dlen = bitset (dlen,rd,d);
rd = rd -1 ;
end
rl = rl -1 ;
end
if (dlen > 10000000 )
clear a ;
return ;
end
a = uint8(zeros(dlen,1)) ;
rd = double(dlen * 8) ;
rl = double(s(1)*s(2)-s(2)) ;
for i=2:s(1)
for j=1:s(2)
if rnd(i,j)<rd/rl
d = bitget (round(r(i,j)/p) ,1) ;
a = z_set_bit (a,rd,d) ;
rd = rd - 1 ;
end
rl = rl - 1 ;
end
end
Remember: a needs to be returned ALLWAYS!
The error is not in that specific line, but in the "whole" function itself.
Your problem is that Matlab thinks that a its not going to be created. And actually in some case it may not be created.
The following line in the beginning of your function should do the trick
a=0; % well, or a=NaN; or whatever you want to return
Additionally, don't clear a in if (dlen > 10000000 ).