Programacion de bases de datos en OOoBasic

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    2 Favorites & 1 Group

    Programacion de bases de datos en OOoBasic - Presentation 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

    + Alexandro ColoradoAlexandro Colorado, 2 years ago

    custom

    4762 views, 2 favs, 4 embeds more stats

    Programacion de OpenOffice.org

    More info about this document

    CC Attribution License

    Go to text version

    • Total Views 4762
      • 4753 on SlideShare
      • 9 from embeds
    • Comments 0
    • Favorites 2
    • Downloads 126
    Most viewed embeds
    • 5 views on http://bdramy.blogspot.com
    • 2 views on http://www.accenture-blogpodium.nl
    • 1 views on http://mmpw.wordpress.com
    • 1 views on http://www.slideshare.net

    more

    All embeds
    • 5 views on http://bdramy.blogspot.com
    • 2 views on http://www.accenture-blogpodium.nl
    • 1 views on http://mmpw.wordpress.com
    • 1 views on http://www.slideshare.net

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories

    Groups / Events