Create MS-Access database

Just starting out? Need help? Post your questions and find answers here.
User avatar
silvercover
User
User
Posts: 86
Joined: Sat Aug 04, 2007 6:57 pm

Create MS-Access database

Post by silvercover »

Hi,

How can I make *.mdb or *.accdb files by coding on run-time in PB?

Thanks.
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Create MS-Access database

Post by spikey »

I'm not sure you can. The whole point of the Access runtime is that design features are disabled or not installed. You need a full install of Access to do any design work. However, if you create a complete but minimal database - ie all tables, forms, reports etc that you need to work with but without any content in the database tables (or the minimum that you need to get the thing off the ground) - then this you could distribute with the runtime.

PB supports SQLite directly which is fine for single user applications, or PostgreSQL for multi-user applications, or ODBC too...
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Create MS-Access database

Post by ts-soft »

Code: Select all

#ODBC_ADD_DSN = 1

Procedure CreateEmptyMDB(databasename.s, user.s = "", pass.s = "")
  Protected strDriver.s, strAttributes.s, L.l, result.l
  Protected *buffer.Character, len.l
  
  If FileSize(databasename) > 0
    DeleteFile(databasename)
  EndIf
 
  strDriver = "Microsoft Access Driver (*.mdb)"
  strAttributes + "CREATE_DB=" + #DQUOTE$ + databasename + #DQUOTE$ + " General"
  strAttributes + ";UID=" + user
  strAttributes + ";PWD=" + pass + ";"
  
  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L

  result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, strDriver, strAttributes)   ; Call the function you need from the ODBC library with the right details

  ProcedureReturn result
  
EndProcedure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Create MS-Access database

Post by Kwai chang caine »

Waouuuuh Cool :shock:
Thanks TsSoft 8)
ImageThe happiness is a road...
Not a destination
User avatar
silvercover
User
User
Posts: 86
Joined: Sat Aug 04, 2007 6:57 pm

Re: Create MS-Access database

Post by silvercover »

Thank you ts-soft. It works perfect. :D
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Create MS-Access database

Post by ts-soft »

you are welcome :D
here some more functions special for mdb

Code: Select all

#ODBC_ADD_DSN = 1

Procedure RepairMDB(databasename.s, user.s = "", pass.s = "")
  Protected name.s, strDriver.s, strAttributes.s, L.l, result.l
  Protected *buffer.Character, len.l
  
  name = GetFilePart(databasename)
  name = Left(name, Len(name) - (Len(GetExtensionPart(name)) + 1))

  strDriver = "Microsoft Access Driver (*.mdb)"
  strAttributes + "REPAIR_DB=" + #DQUOTE$ + databasename + #DQUOTE$
  strAttributes + ";UID=" + user
  strAttributes + ";PWD=" + pass + ";"

  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L
 
  result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, strDriver, strAttributes)   ; Call the function you need from the ODBC library with the right details

  ProcedureReturn result
  
EndProcedure

; ***************************************************************************************

Procedure CompactMDB(databasename.s, user.s = "", pass.s = "")
  
  Protected strDriver.s, strAttributes.s, L.l, result.l
  Protected *buffer.Character, len.l
  
  strDriver = "Microsoft Access Driver (*.mdb)"
  strAttributes + "COMPACT_DB=" + #DQUOTE$ + databasename + #DQUOTE$ + " " + #DQUOTE$ + databasename + #DQUOTE$+ " General"
  strAttributes + ";UID=" + user
  strAttributes + ";PWD=" + pass + ";"
  
  *buffer = @strAttributes
  len = Len(strAttributes) - 1
  For L = 0 To len
    If *buffer\c = ';'
      *buffer\c = 0
    EndIf
    *buffer + SizeOf(Character)
  Next L
  
  result = SQLConfigDataSource_(0, #ODBC_ADD_DSN, strDriver, strAttributes)   ; Call the function you need from the ODBC library with the right details
  
  ProcedureReturn result
  
EndProcedure
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
User avatar
silvercover
User
User
Posts: 86
Joined: Sat Aug 04, 2007 6:57 pm

Re: Create MS-Access database

Post by silvercover »

Again thanks for providing us more functions.

since we can not make tables on run-time in PB using ODBC, Is it useless to have above functionality according to this article?
http://msdn.microsoft.com/en-us/library ... 12%29.aspx

:? :!:
User avatar
spikey
Enthusiast
Enthusiast
Posts: 750
Joined: Wed Sep 22, 2010 1:17 pm
Location: United Kingdom

Re: Create MS-Access database

Post by spikey »

Oh - I think maybe we're talking about two different things here...

There are two versions of Microsoft Access - the full version from the Office suite and a free, redistributable version that Microsoft call the "Microsoft Access Run-time" version. The Access Run-time is designed to support pre-existing Access applications/databases on desktop computers that don't have the full version of Access installed.

You can't create new databases using the "Microsoft Access Run-time" redistributable - because this would mean everyone could create Access databases without paying for an Office license... Sorry I thought that's what you meant when you said "on run-time".

You can create new Access databases with PB through ODBC during a PB program's run-time, as ts-soft's posting shows...

Sorry if I caused confusion...
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: Create MS-Access database

Post by ts-soft »

You can add a dsn to the odbc driver at runtime and remove it!

Download the PBOSL Sources and have a look at ExDatabase.pbi !
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
Post Reply