php - False Positive in Sqlite3 Query Result -


i have server sqlite3 db, , client pc.

if send database query via ajax, receive true result on query result, if query has been done.

my problem is: if turn off server while doing db queries, can receive false positive, because query done not fixed in hard disk memory!

example:

via ajax:

var testo_query='insert comanda terminale,perc_iva,id,cod_articolo,ordinamento,peso_ums,ultima_portata,numero_conto,nodo,cat_variante,dest_stampa,portata,desc_art,quantita,prezzo_un,categoria,ntav_comanda,operatore,tipo_record,stato_record,                                     prog_inser,posizione) values ("null","22","dav_20160629110600158","151","00","","","1","006","1","51","4","tartufo nocciola","1","5.00",  var dbtype='sqlite';  var dbname='provaintellinet.sqlite';                                     "0","a5","davide","corpo","attivo","6","conto");';  $.ajax({                 type: "post",                 async: true,                 url: comanda.url_server + 'classi_php/db_realtime_cassa.lib.php',                 data: {                     type: dbtype,                     db_name: dbname,                     query: testo_query                 },                 datatype: "json",                 timeout: 10000,                  success: function (dati) {                      console.log("query_cassa_success", dati);                      //i receive "true" result here                       }                  }              });` 

that's server side:

<?php  //header('access-control-allow-origin: *');  // importante !! //se non faccio così, ai warning mi da error e ripete due volte la sincronia error_reporting(0);  $sql = $_post['query'];  //mysql @$host = $_request['db_host']; @$user = $_request['db_user']; @$paas = $_request['db_pass'];  $db_name = $_request['db_name']; $db_type = $_request['type'];  $prefix = '../';  $db2 = null;  if ($db_type === 'mysql') {     $db2 = new mysqli($host, $user, $pass, $db_name); } else {     $db2 = new sqlite3($prefix . $db_name); }  $result = false;  $i = 0; while ($result === false && $i < 10) {      $ms = "0." . rand(6, 9);     sleep($ms);     $result = $db2->query($sql);      if ($result !== false) {         $risultato_booleano = "true";         break;     }      $risultato_booleano = "false";     $i++; }  if (strpos(strtolower($sql), 'select') === false) {     $db2->close(); } else {     if ($db_type === 'mysql') {         ($i = 1; $riga = $result->fetch_assoc(); $i++) {             $prodotti[$i] = $riga;         }     } else {         ($i = 1; $riga = $result->fetcharray(sqlite3_assoc); $i++) {             $prodotti[$i] = $riga;         }     } } $db2->close();   if (@json_encode($prodotti) !== null && @json_encode($prodotti) !== 'null') {     echo json_encode($prodotti); } else {     echo $risultato_booleano; } 

why?

i don't know mean 'false positive' sqlite has robust acid support. can read (in extreme detail) how achieved in atomic commit in sqlite.

to benefit must use transactions:

// start transaction. $db2->exec('begin');  ... insert/update/delete/etc. ...  // commit transaction. $db2->exec('commit'); // - or - discard transaction. $db2->exec('rollback'); 

Comments

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -