aviario Active Member Licensed User Longtime User Sep 28, 2015 #1 Se puede saber si existe una columna en sqlite y si no existe como agregarla un saludo Paco Last edited: Sep 28, 2015
netsistemas Active Member Licensed User Longtime User Sep 28, 2015 #2 Puedes hacer un select COLUMNA_A_BUSCAR FROM TABLA where 1=0. Con el where haces que la SQL se ejecute rápidamente. Controla el error con TRY CATH. Si da error deberás ejecutar la instrucción para añadir la columna en MySql. Algo asi: ALTERTABLE{tableName}ADDCOLUMN COLNew {type}; ---- you can execute this SQL: SELECT COLUMN_NAME FROM TABLE WHERE 1=0 With TRY CATCH capture ERROR and if error you must execute a query: ALTERTABLE{tableName}ADDCOLUMN COLNew {type}; -----
Puedes hacer un select COLUMNA_A_BUSCAR FROM TABLA where 1=0. Con el where haces que la SQL se ejecute rápidamente. Controla el error con TRY CATH. Si da error deberás ejecutar la instrucción para añadir la columna en MySql. Algo asi: ALTERTABLE{tableName}ADDCOLUMN COLNew {type}; ---- you can execute this SQL: SELECT COLUMN_NAME FROM TABLE WHERE 1=0 With TRY CATCH capture ERROR and if error you must execute a query: ALTERTABLE{tableName}ADDCOLUMN COLNew {type}; -----
aviario Active Member Licensed User Longtime User Sep 28, 2015 #3 Gracias ya lo he solucionado pongo el código por si alguien le hace falta Sub Comprobar_Columnas Dim Txt As String Dim NoExisteColumna As Boolean=True Dim A As String Txt = "pragma table_info(" & TablaB & ")" Midb.Cursor1 = Midb.SQL1.ExecQuery(Txt) If Midb.Cursor1.RowCount > 0 Then For i=0 To Midb.Cursor1.RowCount-1 Midb.Cursor1.Position=i A=Midb.Cursor1.GetString("name") If A="Fecha_Lote" Then NoExisteColumna=False Exit End If Next End If If NoExisteColumna=True Then Midb.SQL1.ExecNonQuery("ALTER TABLE CONFIGUVENTAS add Fecha_Lote BLOB") End If Midb.Cursor1.Close
Gracias ya lo he solucionado pongo el código por si alguien le hace falta Sub Comprobar_Columnas Dim Txt As String Dim NoExisteColumna As Boolean=True Dim A As String Txt = "pragma table_info(" & TablaB & ")" Midb.Cursor1 = Midb.SQL1.ExecQuery(Txt) If Midb.Cursor1.RowCount > 0 Then For i=0 To Midb.Cursor1.RowCount-1 Midb.Cursor1.Position=i A=Midb.Cursor1.GetString("name") If A="Fecha_Lote" Then NoExisteColumna=False Exit End If Next End If If NoExisteColumna=True Then Midb.SQL1.ExecNonQuery("ALTER TABLE CONFIGUVENTAS add Fecha_Lote BLOB") End If Midb.Cursor1.Close