Estuve creando una base de datos de un archivo de texto. Son unos 370 registros y es que tarda un "poco" en crear la base.
No sé si puedo optimizar algo más el código. Me crea la base y la tabla, pero tarda por lo menos casi 2 minutos.
¿ Cómo podría acelerar un poco este código ?.
' 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 &/ "listajuegos.txt"
hfile = Open ruta For Input
AbrirBase()
CrearTabla()
hcon.Close()
hcon.Name = basenombre
hcon.Open
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
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
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 &/ "listajuegos.txt"
hfile = Open ruta For Input
AbrirBase()
CrearTabla()
hcon.Close()
hcon.Name = basenombre
hcon.Open
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
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
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
¿ Son obligatorios los 30 segundos del wait ?.
El archivo creado esta entero y solo mide 15K!!!!....me muero si fuera la base 10 veces mas grande.
Saludos