He retocado lo mínimo del ejemplo.
' gambas module file
Private $hcon As Connection
Private basenombre As String = "juegosAmiga.sqlite"
Public Sub Main()
Dim hfile As File
Dim linea As String
Dim ruta As String
Dim re As New RegExp
Dim palabras As New String[]
ruta = Application.Path &/ "lista_juegos_amiga.txt"
hfile = Open ruta For Input
AbrirBase()
CrearTabla()
$hcon.Close()
$hcon.Name = basenombre
$hcon.Open
$hcon.Begin ' Añadido
While Not Eof(hfile)
Line Input #hfile, linea
If Len(linea) > 1 Then
linea = LTrim(linea)
' No quiero lineas que contengan LISTA,NOMBRE,-
If Not re.Match(linea, "\\A(LISTA|NOMBRE|-)") Then
palabras = Split(Replace(linea, " ", "\n"), "\n", Null, True)
$hcon.Exec("insert into juegos values (&1,&2,&3,&4,&5)", Null, Trim(palabras[0]), Trim(palabras[1]), Trim(palabras[2]), Trim(palabras[3]))
Endif
Endif
Wend
$hcon.Commit 'Añadido
Close #hfile
CerrarConexion()
End
Public Sub AbrirBase()
$hcon = New Connection
With $hcon
.Type = "sqlite3"
.Host = User.Home &/ "Prueba/Bases/"
.Name = ""
End With
$hcon.Open
If Not $hcon.Databases.Exist(basenombre) Then
$hcon.Databases.Add(basenombre)
'Wait 0.3 'Eliminado
$hcon.Close
$hcon.Name = basenombre
$hcon.Open
Endif
End
Public Sub CrearTabla()
Dim hTable As Table
If Not $hcon.Tables.Exist("juegos") Then
hTable = $hcon.Tables.Add("juegos")
With hTable.Fields
.Add("idjuego", db.Serial)
.Add("titulo", db.String, 50)
.Add("categoria", db.String, 50)
.Add("discos", db.Integer)
.Add("numdiscos", db.String)
End With
hTable.PrimaryKey = ["idjuego"]
hTable.Update
Endif
End
Public Sub CerrarConexion()
If $hcon = Null Then Return
$hcon.Close()
$hcon = Null
End
Private $hcon As Connection
Private basenombre As String = "juegosAmiga.sqlite"
Public Sub Main()
Dim hfile As File
Dim linea As String
Dim ruta As String
Dim re As New RegExp
Dim palabras As New String[]
ruta = Application.Path &/ "lista_juegos_amiga.txt"
hfile = Open ruta For Input
AbrirBase()
CrearTabla()
$hcon.Close()
$hcon.Name = basenombre
$hcon.Open
$hcon.Begin ' Añadido
While Not Eof(hfile)
Line Input #hfile, linea
If Len(linea) > 1 Then
linea = LTrim(linea)
' No quiero lineas que contengan LISTA,NOMBRE,-
If Not re.Match(linea, "\\A(LISTA|NOMBRE|-)") Then
palabras = Split(Replace(linea, " ", "\n"), "\n", Null, True)
$hcon.Exec("insert into juegos values (&1,&2,&3,&4,&5)", Null, Trim(palabras[0]), Trim(palabras[1]), Trim(palabras[2]), Trim(palabras[3]))
Endif
Endif
Wend
$hcon.Commit 'Añadido
Close #hfile
CerrarConexion()
End
Public Sub AbrirBase()
$hcon = New Connection
With $hcon
.Type = "sqlite3"
.Host = User.Home &/ "Prueba/Bases/"
.Name = ""
End With
$hcon.Open
If Not $hcon.Databases.Exist(basenombre) Then
$hcon.Databases.Add(basenombre)
'Wait 0.3 'Eliminado
$hcon.Close
$hcon.Name = basenombre
$hcon.Open
Endif
End
Public Sub CrearTabla()
Dim hTable As Table
If Not $hcon.Tables.Exist("juegos") Then
hTable = $hcon.Tables.Add("juegos")
With hTable.Fields
.Add("idjuego", db.Serial)
.Add("titulo", db.String, 50)
.Add("categoria", db.String, 50)
.Add("discos", db.Integer)
.Add("numdiscos", db.String)
End With
hTable.PrimaryKey = ["idjuego"]
hTable.Update
Endif
End
Public Sub CerrarConexion()
If $hcon = Null Then Return
$hcon.Close()
$hcon = Null
End
He añadido antes del bucle While como comentaba Shordi.
He eliminado el tiempo de espera de los 30 mS. ¿ Obligatorio en sqlite ?.
Y poco más. Me he fijado que esta base de datos no usa Result.
Pero funciona.
Supongo que como es solo la creación de la base de datos, no hay ninguna consulta, por lo tanto no hay un resultado de la misma.
¿ Qué opináis del resultado ?. Creo que no tendré que comerme el coco por ahora con los archivos csv..oooooooh..
Saludos