Eccola.
Public Sub addtable(tabella as String)
// aggiunge una tabella all'array delle tabelle bloccate
tabelle.Append(tabella)
End Sub
Public Sub constructor(nomeprocedura as string)
procedura = nomeprocedura
End Sub
Public Sub destructor()
if tabelle.Ubound > -1 then
// probabilmente non sono state sbloccate tutte le tabelle
self.unlock
end if
End Sub
Public Function lock() as Boolean
if tabelle.Ubound < 0 then
Return true
exit Function
end if
// blocca una o più tabelle
// se una di queste è già bloccata mi fermo
// e ritorno false
If Not app.db.Connected() then
dim ko as new koalamsgbox
ko.Visualizza(app.msg_errore_aperturadatabase + ": " + app.db.errormessage,"Blocco Tabelle")
ko.Show
Return false
exit Function
else
// 21/05/2014 Mods per codicepage Mysql
if app.dbdatabasetype = "MySQL" then app.db.SQLExecute("SET NAMES utf8 COLLATE utf8_general_ci; SET CHARACTER SET utf8")
Dim sql As String
sql = ""
sql = sql + "SELECT * from semafori "
'sql = sql + "WHERE utente = '" + procedure.utente + "' "
if tabelle.Ubound > 0 then
sql = sql + "WHERE tabella in ("
sql = sql + "'" + join(tabelle(),"','") + "'"
sql = sql + ");"
else
sql = sql + "WHERE tabella = '" + tabelle(0) + "' "
sql = sql + "AND utente <> '" + app.utente + "';"
end if
dim rsitem as RecordSet
rsitem = app.db.SQLSelect(sql)
if app.db.Error then
dim ko as new koalamsgbox
ko.Visualizza("Errore durante la selezione dei dati dalla tabella semafori : " + app.db.ErrorMessage,"Blocco Tabelle")
ko.Show
Return false
exit Function
else
if rsitem.eof then
// perfetto non ho blocchi !!!
// quindi andesso li metto
for contatore as integer = 0 to tabelle.Ubound
dim row as new DatabaseRecord
row.Column("utente") = app.utente
row.Column("procedura") = procedura
row.Column("tabella") = tabelle(contatore)
row.Column("host") = gethostname()
app.db.InsertRecord("semafori",row)
if app.db.Error then
dim ko as new koalamsgbox
ko.Visualizza("Errore durante l'inserimento di un blocco nella tabella semafori : " + app.db.ErrorMessage,"Blocco Tabelle")
ko.Show
Return false
exit Function
else
app.db.Commit()
if app.db.Error then
dim ko as new koalamsgbox
ko.Visualizza("Errore durante l'apporto delle modifiche alla tabella semafori : " + app.db.ErrorMessage,"Blocco Tabelle")
ko.Show
Return false
exit Function
end if
end if
next
Return true
exit Function
else
dim msg as string
msg = "Attenzione, alcune tabelle risultano impegnate : " + EndOfLine
while not rsitem.eof
msg = msg + "- " + rsitem.Field("utente").utfValue + ", Proc. : " + rsitem.Field("procedura").utfValue + EndOfLine
rsitem.MoveNext
wend
msg = msg + "attendere qualche secondo e riprovare"
dim ko as new koalamsgbox
ko.Visualizza(msg,"Blocco Tabelle")
ko.Show
Return false
end if
end if
end if
End Function
Public Sub unlock()
If Not app.db.Connected() then
dim ko as new koalamsgbox
ko.Visualizza(app.msg_errore_aperturadatabase + ": " + app.db.errormessage,"Blocco Tabelle")
ko.Show
exit sub
else
// 21/05/2014 Mods per codicepage Mysql
if app.dbdatabasetype = "MySQL" then app.db.SQLExecute("SET NAMES utf8 COLLATE utf8_general_ci; SET CHARACTER SET utf8")
Dim sql As String
sql = ""
sql = sql + "DELETE from semafori "
sql = sql + "WHERE utente = '" + app.utente + "' "
if tabelle.Ubound > 0 then
sql = sql + "AND tabella in ("
sql = sql + "'" + Join(tabelle(),"','") + "'"
sql = sql + ");"
else
sql = sql + "AND tabella = '" + tabelle(0) + "';"
end if
app.db.SQLExecute(sql)
if app.db.Error then
dim ko as new koalamsgbox
ko.Visualizza("Errore durante lo sbloccaggio delle tabelle : " + app.db.ErrorMessage,"Blocco Tabelle")
ko.Show
exit sub
else
app.db.Commit
if app.db.Error then
dim ko as new koalamsgbox
ko.Visualizza("Errore durante l'apporto delle modifiche alla tabella semafori : " + app.db.ErrorMessage,"Blocco Tabelle")
ko.Show
exit sub
end if
end if
end if
End Sub
Proprietà :
procedura as string
tabelle() as string
koalamsgbox è una finestra con un timer che la chiude dopo due secondi