Created
October 30, 2023 21:16
-
-
Save run-dlang/d202074334219b025443ea48d68dfeab to your computer and use it in GitHub Desktop.
Code shared from run.dlang.io.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import std.stdio; | |
import sqlite; | |
void main() | |
{ | |
SQLite db = new SQLite(); // Crea una instancia de la base de datos | |
if (db.open("mi_basededatos.db") == SqlResult.SQL_OK) | |
{ | |
// Realiza una consulta simple | |
string query = "SELECT * FROM tabla"; | |
SQLiteStmt stmt; | |
if (db.prepare(query, stmt) == SqlResult.SQL_OK) | |
{ | |
while (stmt.step() == SqlResult.SQL_ROW) | |
{ | |
writefln("ID: %s, Nombre: %s", stmt.columnText(0), stmt.columnText(1)); | |
} | |
stmt.finalize(); | |
} | |
else | |
{ | |
writeln("Error al preparar la consulta."); | |
} | |
db.close(); | |
} | |
else | |
{ | |
writeln("No se pudo abrir la base de datos."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment