ADORDD sample with checking for existence of a table

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 2 times

ADORDD sample with checking for existence of a table

Post by sudip »

Hello Friends,

I was searching how to check whether a particular table exists in a Access database using ADORDD for a long time.

Now, a very simple (quick and dirty? ;) ) solution came to my mind. I modified ADORDD.1 sample. Please check and send your comments.

Code: Select all

/*
 * MINIGUI - Harbour Win32 GUI library Demo
 *
 * Copyright 2002-2008 Roberto Lopez <harbourminigui@gmail.com>
 * http://harbourminigui.googlepages.com/
 * Based on ADORDD samples included in Harbour distribution

*/

#include "adordd.ch"
#include "minigui.ch"

function Main()

	DEFINE WINDOW Form_1 ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 480 ;
		TITLE 'MiniGUI Browse Demo)' ;
		MAIN NOMAXIMIZE ;
		ON INIT CreateTable() ;
		ON RELEASE CloseTable()

		@ 10,10 BROWSE Browse_1									;
			WIDTH 610  										;
			HEIGHT 390 										;	
			HEADERS { 'First' , 'Last' , 'Age' } ;
			WIDTHS { 150 , 150 , 150 } ;
			WORKAREA Table1 ;
			FIELDS { 'table1->First' , 'table1->Last' , 'table1->Age' } 

	END WINDOW

	CENTER WINDOW Form_1

	Form_1.Browse_1.SetFocus

	ACTIVATE WINDOW Form_1

return nil


Function ADOTableExists(cDatabase, cTable, cAlias)

       // following condition checking was added as reported by Swapan
	if !file(cDatabase)
		return .f.
	endif

	if select(cAlias) > 0
		return .t.
	endif
	
	use &cDatabase via "ADORDD" TABLE cTable alias &cAlias
	if select(cAlias) = 0
		return .f.
	endif
	select &cAlias
	use
	return .t.


Procedure CreateTable

	if !ADOTableExists("test2.mdb", "table1", "table1")
	   DbCreate( "test2.mdb;table1", { { "FIRST",   "C", 10, 0 },;
                                   { "LAST",    "C", 10, 0 },;
                                  { "AGE",     "N",  8, 0 } }, "ADORDD" )
	endif                                  

   USE test2.mdb VIA "ADORDD" TABLE "table1" alias table1
   
   APPEND BLANK
   table1->First   = "Homer"
   table1->Last    = "Simpson"
   table1->Age     = 45

   APPEND BLANK
   table1->First   = "Lara"
   table1->Last    = "Croft"
   table1->Age     = 32

   GO TOP

Return

Procedure CloseTable

   USE

Return

With best regards.

Sudip
With best regards,
Sudip

User avatar
Rathinagiri
Posts: 5295
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 183 times
Been thanked: 199 times
Contact:

Post by Rathinagiri »

Thanks Sudip.

You mean select(cAlias) > 0?
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
sudip
Posts: 1446
Joined: Sat Mar 07, 2009 11:52 am
Location: Kolkata, WB, India
Has thanked: 5 times
Been thanked: 2 times

Post by sudip »

rathinagiri wrote:Thanks Sudip.

You mean select(cAlias) > 0?
Previously I forgot to check whether cDatabase exists or not. This gave error if database didn't exist (confirmed by Swapan).
Then I added
if !file(cDatabase)
return .f.
endif

But, I am not satisfied with Access. Here I can't use Index. I suppose main power is ADODB!!! As of now, I am not comfortable with it. :(

My idea was - to create a software with DBFCDX RDD, then transform it into a good DBMS. :roll:

Regards.

Sudip
With best regards,
Sudip

User avatar
swapan
Posts: 242
Joined: Mon Mar 16, 2009 4:23 am
Location: Kolkata, India
Contact:

Post by swapan »

Looking forward to other members' experience & opinion on the issue raised by Sudip.
Thanks & Regards,
Swapan Das

http://www.swapandas.com/

User avatar
mustafa
Posts: 967
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 187 times
Contact:

Post by mustafa »

Hola amigos:
Sobre el tema iniciado Sudip sobre ADORDD , considero que hay personas
que empiezan en programación de base de datos ,o sus conocimientos sobre
el lenguaje son escasos sobre algunos temas de dicha programación, como me
ocurre a mi en algunas materias ,que he aprendido muchas veces , mirando y
copiando de otros compañeros con sus magníficos trabajos.
Mi idea es intentar mejorar el ejemplo que ellos aportan.
Como el ejemplo iniciado por Sudip.

Personalmente en todo ejemplo, me interesa que esté definido todo el proceso
básico, Crear Nuevos Registros, Modificar Registros, Buscar Registros, Borrar
Registros y Crear Listado en Informes Impresos.

Este ejemplo solo intenta mostrar estas características basicas, que cuando eres
principiante te gusta que el ejemplo esté completo en las acciones básicas.

Dejo el hilo abierto pues mis humildes conocimientos, son escasos sobre el
tema de ADORDD , imprescindible, Adordd.ch y Adordd.prg aportados por
el amigo gfilatov

http://hmgforum.com/viewtopic.php?f=5&t ... d&start=10" onclick="window.open(this.href);return false;" onclick="window.open(this.href);return false;

Compilar el ejemplo con HMG 3.1.5 para que no salga Error con SETWINDOWCURSOR
Mustafa

*-----------------------------------------------------------------------------------------------*
Hello friends :
On the matter started by Sudip about ADORDD, I think that there are people
programming starting database or their knowledge about
language are scarce on some issues of such programming , as it
happens to me in some areas, I have learned many times, watching and
copying from other students with their magnificent works .
My idea is to try to perform the example they provide.
As the example started by Sudip .

Personally in every example, I am interested that the whole Basic process to be defined,
Create New Record , Edit Record , Find Record , Delete Records and Reports Creating List Forms .

This example just tries to show these basic characteristics, we
like when we are beginner, example is completed in the basic actions.

I leave the door opened as my humble knowledge are scarce on the
ADORDD theme, essential , and Adordd.ch , Adordd.prg provided by the
gfilatov friend

http://hmgforum.com/viewtopic.php?f=5&t ... d&start=10" onclick="window.open(this.href);return false;" onclick="window.open(this.href);return false;

Compile the example with HMG 3.1.5 to not error out with SETWINDOWCURSOR

Mustafa
Attachments
screenshot.jpg
screenshot.jpg (110.76 KiB) Viewed 5291 times
Sample_Adordd.zip
(261.36 KiB) Downloaded 424 times

User avatar
esgici
Posts: 4529
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 406 times
Been thanked: 115 times
Contact:

Post by esgici »

Hola Mustafa
Mustafa wrote:...This example just tries to show these basic characteristics, we
like when we are beginner, example is completed in the basic actions....
Muchas gracias hermano :)

Viva HMG :D
Viva INTERNATIONAL HMG :D

User avatar
danielmaximiliano
Posts: 2286
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 347 times
Been thanked: 61 times
Contact:

Post by danielmaximiliano »

Muchas gracias por Compartir Sudip y Mustafa !!!!!!!
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`. Harbour/HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. := +54901169026142
Telegram Name := DaNiElMaXiMiLiAnO

User avatar
bpd2000
Posts: 1143
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 241 times
Been thanked: 139 times

Post by bpd2000 »

Thanks Sudip, Mustafa
BPD
Convert Dream into Reality through HMG

User avatar
mustafa
Posts: 967
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 187 times
Contact:

Post by mustafa »

Hola amigos
Les presento la nueva version de Base de Datos---> "mdb", con Adordd
He experimentado con dicha base y veo que tiene inconvenientes que no logro
subsanar.

1 ---> Indexacion de los registros
2 ---> Si se Borra toda la Base de Datos se produce un Error
Error WINOLE/1007 El valor de BOF o EOF es True, o el actual registro se elimino
3 ---> Si se saca un Listado por Impresora, cuando retornas al menu principal y se pulsa
Borrar se produce el siguiente Error
Error BASE/1099 Argument error: STR
Solo he podido subsanar el Error 2 con la siguiente accion en ---> Function Eliminar()
IF RECNO() = RECCOUNT()
MsgSTOP("Action not allowed "+CRLF+"There is only one Record ","Attention !")
ACTIVA_BOTO()
RETURN
ENDIF

Tiene que quedar siempre un ultimo registro para que la Base de Datos no quede vacia.
*-----------------------------------------------------------------------------------------------------*
He incorporado un RADIOGROUP con ----> OPTIONS {'Code','Name'}
que facilita la busqueda o por Code o por Name, en ----> Function SearchData()
solo se puede utilizar LOCATE y solo permite Nombre o Numero completo, no deja
operar la busqueda con SEEK.
Listados PDF en Carpeta\backup_files
Si les gusta y quieren experimentar, aqui les dejo este sample

Un saludo
Mustafa

*--------------------------------- Google Translator --------------------------------------------*

Hello friends
I present the new version of Database ---> " mdb " with ADORDD
I have experimented with said base and having problems I see that I can not
remedy .

1 ----> Indexing of records
2 ----> If Clears Database Fails
          Error WINOLE/1007 Either BOF or EOF is True , or the current record has been deleted
3 ----> If a Printer List , when you return to the main menu is removed and pressed
         Delete the following error occurs
          Error BASE/1099 Argument error: STR
I could only correct the error 2 with the following action in --- > Function Eliminar()

IF RECNO() = RECCOUNT()
MsgSTOP("Action not allowed "+CRLF+"There is only one Record ","Attention !")
ACTIVA_BOTO()
RETURN
ENDIF

There must always be one last record to the database does not remain empty.
*-----------------------------------------------------------------------------------------------------*
I have incorporated a RADIOGROUP with ---- > OPTIONS { 'Code ', ' Name' }
facilitating the search or by Code or Name , in ---- > Function SearchData()
LOCATE only be used and only allows full name or number , does not leave
operate the search with SEEK.
Listings PDF in Folder\backup_files
If they like it and want to experiment , here I leave this sample

Regards
Mustafa
Attachments
screenshot2.jpg
screenshot2.jpg (95.9 KiB) Viewed 5077 times
Sample_Adordd.zip
(455.88 KiB) Downloaded 289 times

User avatar
esgici
Posts: 4529
Joined: Wed Jul 30, 2008 9:17 pm
DBs Used: DBF
Location: iskenderun / Turkiye
Has thanked: 406 times
Been thanked: 115 times
Contact:

Post by esgici »

mustafa wrote: I present the new version of Database ---> " mdb " with ADORDD
Muchas gracias hermano :)

I will work to learn using this type of databases via your sample :arrow:

Viva HMG :D
Viva INTERNATIONAL HMG :D

Post Reply