Your SlideShare is downloading. ×
Programacion de bases de datos en OOoBasic
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Programacion de bases de datos en OOoBasic

10,064

Published on

Programacion de OpenOffice.org

Programacion de OpenOffice.org

Published in: Technology
0 Comments
4 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
10,064
On Slideshare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
278
Comments
0
Likes
4
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. Programando bases de datos en OpenOffice.org Por Alexandro “JZA” Colorado
  • 2. De que trata esta presentación?
    • Comenzar una macro
    • Crear una base de datos
    • Llamar la base de datos
    • Procesar sentencias
    • Anatomía del código Basic
    • Otras ideas
  • 3. Como comenzar una macro?
    • Vaya a Herramientas – Macros – Organizar Macro – Nuevo
    • Basic puede llamar a Base como un módulo com.sun.star.sdb.DatabaseContext
    • Basic puede interactuar con base:
      • executeQuery()
      • getConnection()
      • createStatement()
      • executeUpdate()
    • Puedes usar Base para conectarte a bases de datos remotas como Oracle, MySQL y PostgreSQL
  • 4. Diagrama de la logica
    • Componente de DB
    • Seleccionar DB
      • Autenticarse
    • Crear la instrucción
    • Ciclar las instrucciones en toda las tabla
    getByURL (myDatabase) DatabaseContext Statement Loop
  • 5. Conectarte a una DB
    • Script para conectarte a una base de datos existente y registrada en Base usando getByName()
    • REM If the database does not exist, then create it.
    • If NOT FileExists ( dbURL ) Then
    • CreateBinaryDB ( dbURL , bVerbose )
    • End If
    • REM Use the DatabaseContext to get a reference to the database.
    • oBaseContext = CreateUnoService ( "com.sun.star.sdb.DatabaseContext" )
    • oDB = oBaseContext . getByName ( dbURL )
    • oCon = oDB . getConnection ( "" , "" )
    • oStmt = oCon . createStatement ()
    • sTableName$ = "BINDATA"
    • REM First, check to see if the table exists!
    • sSql = "select count(*) from INFORMATION_SCHEMA.SYSTEM_TABLES " & _
    • "where TABLE_NAME='" & sTableName & "' " & _
    • "AND TABLE_SCHEM='PUBLIC'"
    • nCount = 0
    • oResult = oStmt . executeQuery ( sSql )
    • If NOT IsNull ( oResult ) AND NOT IsEmpty ( oResult ) Then
    • oResult .Next()
    • nCount = oResult . getLong ( 1 )
    • End If
  • 6. Insertar comando a una DB
    • Guarda la sentencia a una variable y esta la envia a una función llamada executeQuery()
    • REM If the database does not exist, then create it.
    • If NOT FileExists ( dbURL ) Then
    • CreateBinaryDB ( dbURL , bVerbose )
    • End If
    • REM Use the DatabaseContext to get a reference to the database.
    • oBaseContext = CreateUnoService ( "com.sun.star.sdb.DatabaseContext" )
    • oDB = oBaseContext . getByName ( dbURL )
    • oCon = oDB . getConnection ( "" , "" )
    • oStmt = oCon . createStatement ()
    • sTableName$ = "BINDATA"
    • REM First, check to see if the table exists!
    • sSql = "select count(*) from INFORMATION_SCHEMA.SYSTEM_TABLES " & _
    • "where TABLE_NAME='" & sTableName & "' " & _
    • "AND TABLE_SCHEM='PUBLIC'"
    • nCount = 0
    • oResult = oStmt . executeQuery ( sSql )
    • If NOT IsNull ( oResult ) AND NOT IsEmpty ( oResult ) Then
    • oResult .Next()
    • nCount = oResult . getLong ( 1 )
    • End If
  • 7. Procesar comando a una DB
    • Un bucle el cual va reportando los resultado uno por uno usando un If...Next(), también puedes con When.
    • REM If the database does not exist, then create it.
    • If NOT FileExists ( dbURL ) Then
    • CreateBinaryDB ( dbURL , bVerbose )
    • End If
    • REM Use the DatabaseContext to get a reference to the database.
    • oBaseContext = CreateUnoService ( "com.sun.star.sdb.DatabaseContext" )
    • oDB = oBaseContext . getByName ( dbURL )
    • oCon = oDB . getConnection ( "" , "" )
    • oStmt = oCon . createStatement ()
    • sTableName$ = "BINDATA"
    • REM First, check to see if the table exists!
    • sSql = "select count(*) from INFORMATION_SCHEMA.SYSTEM_TABLES " & _
    • "where TABLE_NAME='" & sTableName & "' " & _
    • "AND TABLE_SCHEM='PUBLIC'"
    • nCount = 0
    • oResult = oStmt . executeQuery ( sSql )
    • If NOT IsNull ( oResult ) AND NOT IsEmpty ( oResult ) Then
    • oResult .Next()
    • nCount = oResult . getLong ( 1 )
    • End If
  • 8. Reportando tus datos Aquí insertamos a la hoja de calculo haciendo un bucle
  • 9. Reportando tus datos
    • Como poner tu información en tus documentos.
    • Este ejemplo tenemos la información en Ooo en la hoja de cálculo en oSheet
    • Result = Stmnt.executeQuery(strSQL)
    • ' we get on the current document
    • firstDoc = ThisComponent.getSheets().getByIndex(y)
    • oDoc = ThisComponent
    • ....
    • While Result.next()
    • oDoc.getSheets().insertNewByName(x, 1 )
    • oSheets( 1 ). getCellbyPosition ( 2 , 2 ).SetString( Result.getString (z))
    • Wend
    • oCon.close()
    Esta función no es funcional ya que no declaramos el contador en getCellByPosition() pero podemos ver Result . getString()
  • 10. Crear DB desde Basic
    • Script para crear una nueva base de datos
    • REM Use "Option Compatible", or you can not use a default argument.
    • Sub CreateBinaryDB (Optional dbURL$ = "" , Optional bVerbose = False )
    • Dim oDBContext 'DatabaseContext service.
    • Dim oDB 'Database data source.
    • REM No URL Specified, get one.
    • If dbURL = "" Then dbURL = ChooseAFile ( OOoBaseFilters (), False )
    • REM Still No URL Specified, exit.
    • If dbURL = "" Then Exit Sub
    • If FileExists ( dbURL ) Then
    • If bVerbose Then Print "The file already exists."
    • Else
    • If bVerbose Then Print "Creating " & dbURL
    • oDBContext = createUnoService ( "com.sun.star.sdb.DatabaseContext" )
    • oDB = oDBContext . createInstance ()
    • oDB . URL = "sdbc:embedded:hsqldb"
    • oDB . DatabaseDocument . storeAsURL ( dbURL , Array ())
    • End If
    • End Sub

×