views:

32

answers:

2

I have a PHP process running as a result of a JavaScript AJAX request, which is potentially running for some time and will produce data from time to time. From a usability perspective, I'd like to be able to return data to the JavaScript as soon as it's produced, but this appears not to be possible.

My workaround is to write it to an SQLite database and have another PHP script that runs say once a sec (as a result of another AJAX request) to take the data produced so far and return that, thus allowing the user to be updated on progress in a more timely manner.

Assuming, then, that this is a reasonable approach, the data-writer needs to be able to append a string to the already existing contents of a row. I don't know SQL that well, but the following appears to work:

create table str_table (mystr string);
insert into str_table (mystr) values ("first part of string.");
update str_table set mystr = ((select mystr from str_table) || " Second part of string.");

Is there a more direct way to append to mystr?

The data-reader needs to get the contents of mystr and then clear it. I guess I can do:

begin transaction
select mystr from str_table;
update str_table set mystr = null;
end transaction

but is it possible to do that in a single statement?

Thanks.

A: 

An UPDATE query is the correct way to do it, and there is no way to get-and-set in SQL.

Ignacio Vazquez-Abrams
Ok thanks for the get-and-set info.
clothears
A: 

You should use a simple UPDATE query. Concatenating extra data to a field can be performed as follows :

UPDATE table SET field = field || " Second part of string."

This will append " Second part of string." to the field column, for every row in the table you specified.

wimvds
Ah thanks - that's an excellent simplification!
clothears