Slideshare.net (beta)

 
Post: 
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons



All comments

Add a comment on Slide 1

If you have a SlideShare account, login to comment; else you can comment as a guest


Showing 1-50 of 1 (more)

Programacion de bases de datos en OOoBasic

From jza, 7 months ago

Programacion de OpenOffice.org

682 views  |  0 comments  |  1 favorite  |  20 downloads  |  2 embeds (Stats)
 

Groups/Events

Not added to any group/event

 
 

Privacy InfoNew!

This slideshow is Public

 
CC Attribution License
Embed in your blog
Embed (wordpress.com)
custom

Slideshow Statistics
Total Views: 682
on Slideshare: 679
from embeds: 3* * Views from embeds since 21 Aug, 07

Slideshow transcript

Slide 1: Programando bases de datos en OpenOffice.org Por Alexandro “JZA” Colorado 31 de octubre de 2007

Slide 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 ● 31 de octubre de 2007

Slide 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 31 de octubre de 2007

Slide 4: Diagrama de la logica 1. Componente de DB DatabaseContext 2. Seleccionar DB 1. Autenticarse getByURL 3. Crear la instrucción (myDatabase) 4. Ciclar las instrucciones en toda Statement las tabla Loop 31 de octubre de 2007

Slide 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 31 de octubre de 2007

Slide 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 31 de octubre de 2007

Slide 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 31 de octubre de 2007

Slide 8: Reportando tus datos Aquí insertamos a la hoja de calculo haciendo un bucle 31 de octubre de 2007

Slide 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() 31 de octubre de 2007

Slide 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 31 de octubre de 2007