I see 2 other options:<br><br>a) keep the last (longitude, latitude) pair for every receiver stored in your script, too, besides the db. When a new pair of values arrives, compare it with the current and only if it is different, send the "INSERT" query to the database.<br>
<br>b) When a new pair of values arrives, send a query (or stored procedure) that tells the database to check and "INSERT" only if the pair is different that the latest. <br><br>Pandelis Theodosiou<br><br><br><div class="gmail_quote">
On Mon, May 9, 2011 at 1:50 PM, Albert Brandl <span dir="ltr"><<a href="mailto:albert.brandl@weiermayer.com" target="_blank">albert.brandl@weiermayer.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi!<br>
<br>
In the application I'm currently working on, we gather data from<br>
different sources and store them in a database, but only if the<br>
values have changed.<br>
<br>
One example is GPS information. We don't want to store hundreds of<br>
identical values that are sent by the receiver, so we have to compare the<br>
last written row with the current latitude / longitude pair.<br>
<br>
I use a subclass of NMEARreceiver class to determine the current latitude<br>
and longitude. Then I query the database using a ConnectionPool instance<br>
to get the previous values for latitude and longitude. If the result<br>
differs from the current values, a new entry is stored, again using the<br>
ConnectionPool.<br>
<br>
The problem is: How do I "connect" the current latitude and longitude to<br>
the database query? The query returns a Deferred object, but this expects<br>
a callback with only one argument, the result of the query.<br>
<br>
Storing them as instance variables of NMEAReceiver does not seem to be<br>
the right way, since I don't know how long it takes to query the database<br>
- the relevant GPS information might be overwritten by a new NMEA<br>
telegram when the connection pool finally triggers the callback<br>
<br>
One workaround I've found is to add this information to the SQL query,<br>
but this seems quite weird to me (and doesn't work in the case that the<br>
query does not return a result).<br>
<br>
A different approach would be to implement a callback with three<br>
arguments (result, latitude and longitude), and wrap it in a lambda<br>
function that fills latitude and longitude with the current values.<br>
Would this would be a better way to handle this requirement?<br>
<br>
How would you implement this?<br>
<br>
Thanks & best regards,<br>
<br>
Albert<br>
--<br>
Albert Brandl<br>
Weiermayer Solutions GmbH | Abteistraße 12, A-4813 Altmünster<br>
phone: +43 (0) 720 70 30 14 | fax: +43 (0) 7612 20 3 56<br>
web: <a href="http://www.weiermayer.com" target="_blank">http://www.weiermayer.com</a><br>
<br>
_______________________________________________<br>
Twisted-Python mailing list<br>
<a href="mailto:Twisted-Python@twistedmatrix.com" target="_blank">Twisted-Python@twistedmatrix.com</a><br>
<a href="http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python" target="_blank">http://twistedmatrix.com/cgi-bin/mailman/listinfo/twisted-python</a><br>
</blockquote></div><br><div style="display: inline;"></div>
        <img src="http://www.qtl.co.il/img/copy.png" title="Copy Selction"><a href="http://int.ask.com/web?siteid=10000861&webqsrc=999&l=dis&q=UPDATE" title="Search With Ask" target="_blank"><img src="http://www.ask.com/favicon.ico"></a><img src="http://translate.google.com/favicon.ico" title="Translate With Google">
        
<div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style><style>
qtl {
        position: absolute;
        border: 1px solid #cccccc;
        -moz-border-radius: 5px;
        opacity: 0.2;
        line-height: 100%;
        z-index: 999;
        direction: ltr;
}
qtl:hover,qtl.open {
        opacity: 1;
}
qtl,qtlbar {
        height: 22px;
}
qtlbar {
        display: block;
        width: 100%;
        background-color: #cccccc;
        cursor: move;
}
qtlbar img {
        border: 0;
        padding: 3px;
        height: 16px;
        width: 16px;
        cursor: pointer;
}
qtlbar img:hover {
        background-color: #aaaaff;
}
qtl>iframe {
        border: 0;
        height: 0;
        width: 0;
}
qtl.open {
        height: auto;        
}
qtl.open>iframe {
        height: 200px;
        width: 300px;
}
</style>
        <img src="http://www.qtl.co.il/img/copy.png" title="Copy Selction"><a href="http://int.ask.com/web?siteid=10000861&webqsrc=999&l=dis&q=triple%20" title="Search With Ask" target="_blank"><img src="http://www.ask.com/favicon.ico"></a><img src="http://translate.google.com/favicon.ico" title="Translate With Google">