Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
por qué el orden del bucle cambia al analizar datos en la base de datos sqlite

un documento xml se edita usando una función. Primero, se eliminan todos los archivos duplicados. Luego, el contenido se ingresa en una base de datos sql. Para esto ejecuto un bucle que corresponde a la longitud de los elementos xml (aquí ya convertidos a json). Cuando observo el contenido de la tabla en la base de datos, veo que el orden de las entradas no se corresponde con el orden de la matriz. Entonces, dentro de la consulta de la base de datos de mi servidor, imprimí la variable de ejecución i y vi que comienza en 0 pero 2,3,1 se agregan al final en este orden. Desafortunadamente, no entiendo en absoluto por qué sucede esto y espero que alguien pueda ayudarme aquí.

 function extractquestions(filename){ let questions = []; let sql_insert = 'INSERT INTO Fragen (Titel, Frage) values (?,?)'; fs.readFile('./files/'+filename, function(err, data){ if(err){ throw err; } const xmlDataStr = data; const options = { ignoreAttributes: false, attributeNamePrefix : "attr_" }; const parser = new XMLParser(options); const output = parser.parse(xmlDataStr); for(let i = 0; i<output.quiz.question.length; i++){ //Here the needed Questions are filtered out of the xml (Json) data if(output.quiz.question[i].attr_type == "coderunner"){ questions.push(output.quiz.question[i]); } } //Delete Duplicates from array const filteredQuestions = questions.reduce((acc, current) => { const x = acc.find(item => item.name.text === current.name.text); if (!x) { return acc.concat([current]); } else { return acc; } }, []); for(let i = 0; i<filteredQuestions.length; i++){ db.run(sql_insert, filteredQuestions[i].name.text, filteredQuestions[i], (err, result)=>{ console.log(i); if(err){ throw err; } }); } }); }
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!