MariaDB - CREATE TABLE | text, int(11), tinyint

Post Reply
User avatar
Otto
Posts: 6403
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 24 times
Been thanked: 2 times
Contact:

MariaDB - CREATE TABLE | text, int(11), tinyint

Post by Otto »

Hello
I would like to make an array to create following SQL sting.

CREATE TABLE `bookings` (
`start_date` date DEFAULT NULL,
`end_date` date DEFAULT NULL,
`text` text DEFAULT NULL,
`room` int(11) DEFAULT NULL,
`status` int(11) DEFAULT NULL,
`id` int(11) NOT NULL,
`is_paid` tinyint(1) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;


Can someone please show me how I can create:
Text, int(11) and tinyint(1).

`text` text DEFAULT NULL,
`is_paid` tinyint(1) DEFAULT NULL
`status` int(11) DEFAULT NULL,


local aStru := { ;
{ "start_date", "D", 8, 0 }, ;
{ "end_date", "D", 8, 0 }, ;
{ "text", "C", 30, 0,"latin1" }, ;
{ "room", "N", 4, 0 }, ;
{ "status", "N", 5, 0 }, ;
{ "idPrimary", "+", 3, 0 }, ; // '+' : AutoInc Primary Key
{ "is_paid", "N", 6, 0 } }

Thank you in advance

Otto
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
Otto
Posts: 6403
Joined: Fri Oct 07, 2005 7:07 pm
Has thanked: 24 times
Been thanked: 2 times
Contact:

Re: MariaDB - CREATE TABLE | text, int(11), tinyint

Post by Otto »

Hello,

As I do not know the right syntax for for oCn:CreateTable( cTable, aStru ) I use oCn:Execute( cSql ) and pass the SQL string.

This is working for me.

Mr Rao documented FWH - Built-in MySql/MariaDB functionality very well.
Thank you for creating the LIB and your great work on the LIB.
I put the link here again – sometimes you miss such important information as you do not need it immediately

viewtopic.php?f=3&t=32657&p=191922&hilit=http%3A%2F%2Fdev.mysql.com%2Fdoc%2Frefman%2F5.7%2Fen%2F#p191922


Best regards
Otto

cSql := "CREATE TABLE `planner` ( `start_date` date DEFAULT NULL, `end_date` date DEFAULT NULL, `text` text DEFAULT NULL, `room` int(11) DEFAULT NULL, `status` int(11) DEFAULT NULL, `id` int(11) NOT NULL, `is_paid` tinyint(1) DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=latin1;"
oCn:Execute( cSql )
********************************************************************
mod harbour - Vamos a la conquista de la Web
modharbour.org
https://www.facebook.com/groups/modharbour.club
********************************************************************
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: MariaDB - CREATE TABLE | text, int(11), tinyint

Post by nageswaragunupudi »

Code: Select all | Expand

  MYSQL_TinyIntAsLogical( .t. )

   aStru := { ;
   { "start_date",   "D", 8, 0 }, ;
   { "end_date",     "D", 8, 0 }, ;
   { "text",         "C", 30, 0,"latin1" }, ;
   { "room",         "N", 5, 0 }, ;
   { "status",       "N", 5, 0 }, ;
   { "idPrimary",    "+", 3, 0 }, ;
   { "is_paid",      "L", 1, 0 }  }

   oCn:DropTable( "rooms" )
   oCn:CreateTable( "rooms", aStru, , "latin1" )

   ? oCn:CreateTableSQL( "rooms" )

 
Regards

G. N. Rao.
Hyderabad, India
User avatar
goosfancito
Posts: 1955
Joined: Fri Oct 07, 2005 7:08 pm

Re: MariaDB - CREATE TABLE | text, int(11), tinyint

Post by goosfancito »

Hola.-

Code: Select all | Expand

    ::oCnx:DropTable( "tbsucursal" )

      aDatos := { ;
                  { "id", "n", 2, 0, "PRI" }, ;
                  { "nombre", "c", 120, 0 } ;
                }

      lValue := ::oCnx:createtable( "tbsucursal", aDatos, .t. )

      IF ( lValue )
         ::oCnx:insert( "tbsucursal", "nombre", { "Reconquista" } )
         ::oCnx:insert( "tbsucursal", "nombre", { "Rafaela" } )
      ENDIF


al hacer:

Code: Select all | Expand

    browser ::oCnx:tbsucursal

no me funciona el indice primario "id" que estoy haciendo mal?
FWH 21.02
Harbour 3.2.0dev (r2104281802)
Copyright (c) 1999-2021, https://harbour.github.io/
User avatar
nageswaragunupudi
Posts: 10721
Joined: Sun Nov 19, 2006 5:22 am
Location: India
Been thanked: 8 times
Contact:

Re: MariaDB - CREATE TABLE | text, int(11), tinyint

Post by nageswaragunupudi »

Code: Select all | Expand


::oCnx:DropTable( "tbsucursal" )

aDatos := { ;
            { "nombre", "C", 120, 0 } ;
          }

lValue := ::oCnx:createtable( "tbsucursal", aDatos )

IF ( lValue )
   ::oCnx:insert( "tbsucursal", "nombre", { "Reconquista" } )
   ::oCnx:insert( "tbsucursal", "nombre", { "Rafaela" } )
ENDIF

xbrowser ::oCnx:tbsucursal

? ::oCnx:CreateTableSQL( "tbsucursal" )
 


Please use capitals for field datatypes, like "N","C","L","D","T","M".
Do not use "n","c","l","d","t"

In some cases Upper and Lower cases have different significance.

"C" : Creates VarChar
"c" : Creates Binary char field
"M" : Creates Long Text Field
"m" : Creates Long BLOB
Regards

G. N. Rao.
Hyderabad, India
horacio
Posts: 1364
Joined: Wed Jun 21, 2006 12:39 am
Location: Capital Federal Argentina

Re: MariaDB - CREATE TABLE | text, int(11), tinyint

Post by horacio »

Hi Rao

"C" : Creates VarChar
"c" : Creates Binary char field
"M" : Creates Long Text Field
"m" : Creates Long BLOB


where can you see all the options? Thank you

Saludos
Post Reply