How to clear/flush messag queue buffer in VxWorks? - message-queue

i would like to know, is there any method to flush all messages which are pipelined on 1 msgQId?????

There is no built-in API to flush all messages from a message queue.
If all you want to do is discard all messages from a queue, here is a quick way to do this:
void discardQMessages(MSG_Q_ID id) {
while(
msgQReceive(id, NULL, 0, NO_WAIT) != ERROR
) ;
if {errno != S_objLib_OBJ_UNAVAILABLE)
/* Uh oh... got some problem */
}
You should always check errno when you get error from any OS API call.

Related

Problem with handling the result of SELECT query in MYSQL C API

I'm getting a Internal Server Error with one of my scripts. I'm using MYSQL C API. https://dev.mysql.com/doc/refman/5.6/en/c-api.html
Here is the corresponding part of my script:
MYSQL *con;
MYSQL_RES *result;
MYSQL_ROW robe;
con = mysql_init(NULL);
if (!mysql_real_connect(valid values)) {
printf("Content-type: text/html\n\n");
printf("Could not connect\n");
exit(0); }
char somequery[512];
//userinput is sanitized beforehand
int sog = sprintf(somequery, "SELECT password from testtab WHERE username='%s'", userinput);
if (sog < 0) {
printf("Content-type: text/html\n\n");
printf("Something went wrong with Sprintf\n");
exit(0); }
int bos = mysql_real_query(con, somequery, strlen(somequery));
if (bos != 0) {
printf("Content-type: text/html\n\n");
printf("The query produced no result\n");
exit(0); }
result = mysql_store_result(con);
if (result == NULL) {
printf("Content-type: text/html\n\n");
printf("No Result Set Produced\n");
exit(0); }
robe = mysql_fetch_row(result);
char *passdb = robe[0];
printf("Content-type: text/html\n\n");
printf("And it is: %s", passdb);
A HTML form submits via POST to this script (part of which is seen above). When I submit a username which exists in the database beforehand, I'm receiving no error. Everything works fine.
The problem arises, when I'm submitting a username that doesn't exist in the said table(testtab). Well, I'm getting 500 Internal Server Error. I have looked at Apache Error log as well: "End of Script output before Headers".
I have tried a few things so far, but none of them worked. Any help is appreciated.
Note: Doing mysql_num_fields(result); in both cases gives 1.
First, you should NEVER store passwords in a database, especially one that is reachable through an online service. exit(0) indicates success. It's also short-circuiting your output before it is completed. You can't just call exit(0) in the middle of producing output. Use some kind of "data not available" string instead.
I have found the solution elsewhere, thanks to the help of some good people. It seems, that I had made a silly mistake as well as needed a thorough understanding of the difference between two MYSQL C API functions.
I'm writing the answer here, in hope of it benefiting others.
The mistakes is here:
robe = mysql_fetch_row(result);
Though it is correct in itself. I fail to check its result. What happens is that when the SQL query is performed using a username that did not exist in the DB beforehand, the result is a empty set (and not a error).
The mysql_store_result and mysql_fetch_row have a slight difference here. While the former will not return NULL if the set is empty, the later will.
All I have to do is add a check after the above line with the logic:
if (robe == NULL) {
//error occured
} else { //go on
}

SSIS Event Handler - How do I get the entire error message?

I've set up a data flow task with a source component (ODBC to Salesforce) that writes rowcounts and any raised error messages to a table.
I've created an OnError event handler that writes the message from System::ErrorDescription to a variable, and then that variable is written to the table.
My problem is that System::ErrorDescription doesn't have the interesting error message, but the summary.
These are the messages being generated in the Progress tab:
[SRC - Extract Account [6]] Error: System.Data.Odbc.OdbcException (0x80131937): ERROR [HY000] INVALID_LOGIN: Invalid username, password, security token; or user locked out.etc, etc,etc
[SSIS.Pipeline] Error: SRC - Extract Account failed the pre-execute phase and returned error code 0x80131937.
System::ErrorDescription only has the [SSIS.Pipeline] error ("SRC - Extract Account failed the pre-execute phase and returned error code 0x80131937").
How do I return the more detailed [SRC - Extract Account [6]] message?
Thanks,
Jason
You could also just query your SSISDB to get the error.
Use event_name to find your error
Try this:
/*
:: PURPOSE
Show the Information/Warning/Error messages found in the log for a specific execution
:: NOTES
The first resultset is the log, the second one shows the performance
:: INFO
Author: Davide Mauri
Version: 1.1
:: VERSION INFO
1.0:
First Version
1.1:
Added filter option on Message Source
Correctly handled the "NULL" filter on ExecutionId
*/
USE SSISDB
GO
/*
Configuration
*/
-- Filter data by execution id (use NULL for no filter)
DECLARE #executionIdFilter BIGINT = NULL;
-- Show only Child Packages or everyhing
DECLARE #showOnlyChildPackages BIT = 0;
-- Show only message from a specific Message Source
DECLARE #messageSourceName NVARCHAR(MAX)= '%'
/*
Implementation
*/
/*
Log Info
*/
SELECT * FROM catalog.event_messages em
WHERE ((em.operation_id = #executionIdFilter) OR #executionIdFilter IS NULL)
AND (em.event_name IN ('OnInformation', 'OnError', 'OnWarning'))
AND (package_path LIKE CASE WHEN #showOnlyChildPackages = 1 THEN '\Package' ELSE '%' END)
AND (em.message_source_name like #messageSourceName)
ORDER BY em.event_message_id;
/*
Performance Breakdown
*/
IF (OBJECT_ID('tempdb..#t') IS NOT NULL) DROP TABLE #t;
WITH
ctePRE AS
(
SELECT * FROM catalog.event_messages em
WHERE em.event_name IN ('OnPreExecute')
AND ((em.operation_id = #executionIdFilter) OR #executionIdFilter IS NULL)
AND (em.message_source_name like #messageSourceName)
),
ctePOST AS
(
SELECT * FROM catalog.event_messages em
WHERE em.event_name IN ('OnPostExecute')
AND ((em.operation_id = #executionIdFilter) OR #executionIdFilter IS NULL)
AND (em.message_source_name like #messageSourceName)
)
SELECT
b.operation_id,
from_event_message_id = b.event_message_id,
to_event_message_id = e.event_message_id,
b.package_path,
b.execution_path,
b.message_source_name,
pre_message_time = b.message_time,
post_message_time = e.message_time,
elapsed_time_min = DATEDIFF(mi, b.message_time, COALESCE(e.message_time, SYSDATETIMEOFFSET()))
INTO
#t
FROM
ctePRE b
LEFT OUTER JOIN
ctePOST e ON b.operation_id = e.operation_id AND b.package_name = e.package_name AND b.message_source_id = e.message_source_id AND b.[execution_path] = e.[execution_path]
INNER JOIN
[catalog].executions e2 ON b.operation_id = e2.execution_id
WHERE
e2.status IN (2,7)
OPTION
(RECOMPILE)
;
I know the question is old, but I had this problem today.
Each error message line fires OnError event.
So to capture all error lines concatenate the value of yours variable.
Something like that:
Dts.Variables["MyErrorVar"].Value = Dts.Variables["MyErrorVar"].Value + Environment.NewLine + Dts.Variables["System::ErrorDescription"].Value.ToString()

Refresh Queries in Threads

I`m using Delphi XE6 and UniDAC and MySQL
I have some TUniQuery components in my DM and I want to Refresh theme repeatedly, so I put some Timers in my main form and in each timer I create a thread and pass a query to it for refreshing data :
for Example :
TUpdateThread = class(TThread)
private
FQuery : TUniQuery;
FResultHandle : THandle;
public
constructor Create(var Query : TUniQuery; ResultHandle : THandle);
protected
procedure Execute; override;
end;
constructor TUpdateThread.Create(var Query: TUniQuery; ResultHandle : THandle);
begin
inherited Create;
Suspend;
FQuery := Query;
FResultHandle := ResultHandle;
FreeOnTerminate := True;
Resume;
end;
procedure TUpdateThread.Execute;
var
Msg : String;
B : Boolean;
begin
try
B := True;
try
FQuery.Refresh;
except
on E:Exception do
begin
B := False;
Msg := 'Error : ' + #13 + E.Message;
SendMessage(FResultHandle, MSG_UPDATERESULT, 2, Integer(Msg));
end;
end;
finally
if B = True then
SendMessage(FResultHandle, MSG_UPDATERESULT, 1, 1);
Terminate;
end;
end;
Sometimes it`s done successfully but many times I got some errors such as AVs or "Net Pack Header ... " error
or sometimes I have problem in my Grids ( Ehlib DBGrid ) such as error in drawing rows or ... ( specially when I use DisableControls and EnableControls )
All of Queries have same connection , I think each Thread should have his own connection, because of all timers intervals are same , I suggest sometimes refreshing queries interrupts each others
In fact, my database is in a VPS server and there is some client applications , I want to have Live-Tables in Clients and update theme repeatedly
What is the best way to achieve that ?
how I should update my Tables without application hangs !
there is some components as TThreadTimer ( or ... ) , is theme useful for this situation ?!
thanks ...
The first issue is here :
constructor TUpdateThread.Create(var Query: TUniQuery; ResultHandle : THandle);
begin
inherited Create; // Create with no arguments
Suspend; // means CreateSuspended = false
FQuery := Query;
FResultHandle := ResultHandle;
FreeOnTerminate := True;
Resume;
end;
Here you create the thread with the default constructor (CreateSuspended = false) where the thread begins running immediately. You call suspend (which is deprecated and should not be used) immediately, but this is still a race condition since your thread may or may not start trying to Refresh your query before you've assigned it. To create the thread in a suspended state use the overload constructor of
inherited Create(true);
Resume is also deprecated. Instead you should use Start;.
Further, you're passing in a TUniQuery to this thread's constructor. We can assume, I imagine, that this query has affinity to the main thread - this is to say that it is (perhaps) a visual component on a form, has databindings to visual components, or is otherwise interacted with by the user or user interface.
The answer, if so, is that you simply cannot do this - a thread cannot modify an object with affinity to another thread. Your interface may be in the middle of retrieving records from the query when the background thread, for example, is simultaneously destroying them in preparation to refresh the query contents. Naturally this will cause all sorts of problems.
The simple solution is to use a regular timer and refresh synchronously on the main thread. If this takes too long then you need to consider a different strategy altogether. We don't really have sufficient information to suggest much further. If network access and I/O is the bottleneck then you might consider asynchronously refreshing to a separate query object owned by the thread, then synchronously assign it to your view components.

OBD-II Perl code hangs after specific number of AT requests

After connecting to a Bluetooth OBD-II adapter, I am able to get
data by sending PID service requests, but they stop exactly after
the same number of requests.
for ( ;; ) {
obj -> write ( "010C\r" );
if ( $data = $obj -> input ) {
print "$data";
}
obj -> write ( "010D\r" );
if ( $data = $obj -> input ) {
print "$data";
}
}
Can you please let me know what could be the problem? I read
somewhere about two options 1) Re-initializing and 2) about
buffer left with CRs. I am looking into those.
(I used Torque on my android with the same OBD-II Bluetooth
adapter and it seems to get the data continuously. So there
must be something wrong in what I am doing).
Thank you for any response.

Groovy Gorm catch util.JDBCExceptionReporter error on save()

I have a problem to catch util.JDBCExceptionReporter during save().
Code:
membership.withTransaction { status ->
try{
def membership = membership.findByUserId(userId)
if(!membership){
membership = new membership(userId: userId, email: userEmail, baseLevel: membership.findByName(membershipName.MEMBER)).save(flush: true)
}
}catch(org.springframework.dao.DataIntegrityViolationException e){
status.setRollbackOnly()
return false
}catch(all){
println "Insert Membership Exception.\n User Id: $userId\n " + e
}
When I create two thread to run this code, it throw a error:
2014-05-06 12:53:07,034 [Actor Thread 5] ERROR util.JDBCExceptionReporter - Duplicate entry 'test#gmail.com' for key 'email'
I don't want to show this error every time when their has two threads doing the same insert, because the first thread will go through and insert successfully, so I don't really care about second one.
My question is how to catch util.JDBCExceptionReporter?
Thanks.
Just guessing:
By default Grails doesn't throw exceptions when saving. To throw integrity exceptions you have to use save(failOnError: true).
So in this case, it's just an internal trace (util.JDBCExceptionReporter is not an exception).
In your case, instead of capturing exceptions I'd use validate before saving so you can get the integrity errors before trying to save.
As lsidroGH said, util.JDBCExceptionReporter is not an exception, it's a log message. It logs both SQLExceptions and SQLWarnings. There is no problem with your code, as one thread will have a save() call that returns true and the other thread's save() will get false.
If you don't want this message to show up in your logs, you will need to increase your log level for org.hibernate.util.JDBCExceptionReporter from ERROR to FATAL but this will potentially exclude valid exceptions you would want logged. Your best bet is to ignore it, as your code works.