ADOdb

Database Abstraction Layer for PHP

User Tools

Site Tools


v5:reference:connection:setcustommetatype

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
v5:reference:connection:setcustommetatype [2021/01/17 01:42] mnewnhamv5:reference:connection:setcustommetatype [2021/01/20 01:30] (current) mnewnham
Line 4: Line 4:
 **From Version 5.22**\\ **From Version 5.22**\\
 ==See Also== ==See Also==
-[[v5:reference:connection:setcustomactualtype|setCustomActualType]]\\+[[v5:reference:connection:getcustommetatypes|getCustomMetaTypes]]\\
 == Syntax == == Syntax ==
   bool setCustomMetaType(   bool setCustomMetaType(
          string $metaType,          string $metaType,
 +         string $actualType,
 +         string $dictionayType,
          mixed $handleAsType=false,          mixed $handleAsType=false,
          mixed $callBack=false          mixed $callBack=false
Line 13: Line 15:
 </WRAP> </WRAP>
 ===== Description ===== ===== Description =====
-The function ''setCustomMetaType()'' takes an input string that represents a database-specific data type, and creates an ADOdb [[v5:dictionary:metatype|metaType]] associated with it. If the physical type is already bound to an existing metaType, the new setting overrides the old. For full functionality, a corresponding [[v5:reference:connection:setcustomactualtype|setCustomActualType()]] command should be issued.+The function ''setCustomMetaType()'' takes an input string that represents a database-specific data type, and creates an ADOdb [[v5:dictionary:metatype|metaType]] associated with it. If any combination of parameters passed are already bound to an existing metaType, the new setting overrides the old. 
 ------------------------------------------------------- -------------------------------------------------------
 ===== $metaType ===== ===== $metaType =====
 An existing or new type. The type definition should be an uppercase alpha-numeric value, e.g. **P** An existing or new type. The type definition should be an uppercase alpha-numeric value, e.g. **P**
-===== $ActualType ===== + 
-A Database specific field type, mapped to the metaType, e.g. **POINT**. This tells ADOdb how to handle the data n inserts and updates.+===== $actualType ===== 
 +The physical data type as provided by the database, for example the POINT data type in the mySQL returns 255.   
 + 
 +===== $dictionaryType ===== 
 +A Database specific field type, mapped to the metaType, e.g. **POINT**. This tells ADOdb how to handle the database will handle the record. 
 ===== $handleAsType ==== ===== $handleAsType ====
-One of the standard [[v5:dictionary:dictionary_index|metaTypes]]. This indicates what type of data the new type is. If not set, then no attempt is made to process the data. +One of the standard [[v5:dictionary:dictionary_index|metaTypes]]. This indicates what type of data the new type is, and how it should be handled prior to insertion. If not set, then no attempt is made to process the data, and an attempt is made to insert the data in the format that it was provided. 
-===== Data Handler =====+ 
 +=====$callback ===== 
 The handler can be one of these types: The handler can be one of these types:
   - Not set: No pre-processing of data prior to insertion of data.   - Not set: No pre-processing of data prior to insertion of data.
Line 37: Line 46:
 */ */
  
-/* 
-* First link the MySQL geometry type to a new metaType 
-*/  
-$ok = $db->setCustomActualType(255,'P'); 
  
 /* /*
-Now tell ADOdb how to handle the data in inserts and updates +A type 'P' is associated with a physical data type of 255 (MYSQLI_TYPE_GEOMETRY)  
-see the entry for setCustomMetaType for an explanation+and we describe it as 'POINT' in the insertion statement. Because we do not want  
 +any changes to the input value, we do not define any processing rules
 */ */
-$ok = $db->setCustomMetaType('P','POINT');+$ok = $db->setCustomMetaType('P',MYSQLI_TYPE_GEOMETRY, 'POINT');
  
 /* /*
Line 57: Line 63:
  
 ==== Using a closure ==== ==== Using a closure ====
-In this example all character fields are converted to lowercase by the anonymous function+In this example all character fields are converted to lowercase by the anonymous function, and are then processed normally as character
 <code php> <code php>
  
Line 67: Line 73:
  };  };
  
-$ok = $db->setCustomMetaType('C','CHAR',$callback);+$ok = $db->setCustomMetaType('C',MYSQLI_TYPE_CHAR, 'CHAR','C', $callback);
 </code> </code>
  
 ===== Using The Custom Type In DataDict Functions ====== ===== Using The Custom Type In DataDict Functions ======
-In this example, we use a custom definition to create a POINT column in a table under MySQL+In this example, we use a custom definition to create a JSON column in a table under MySQL
 <code php> <code php>
 /* /*
 * We must define the custom type before loading the data dictionary * We must define the custom type before loading the data dictionary
 */ */
-$ok = $db->setCustomActualType(255,'P'); +$ok = $db->setCustomMetaType('J', MYSQLI_TYPE_JSON, 'JSON');
-$ok = $db->setCustomMetaType('P','POINT');+
  
 /* /*
Line 89: Line 94:
    COL2 C(32) NOTNULL DEFAULT 'abc',    COL2 C(32) NOTNULL DEFAULT 'abc',
    COL3 N(12.2),    COL3 N(12.2),
-   COL4 P+   COL4 J
   ";   ";
  
Line 101: Line 106:
 COL2                     VARCHAR(32) NOT NULL DEFAULT 'abc', COL2                     VARCHAR(32) NOT NULL DEFAULT 'abc',
 COL3                     NUMERIC(12,2), COL3                     NUMERIC(12,2),
-COL4                     POINT,+COL4                     JSON,
                  PRIMARY KEY (COL1)                  PRIMARY KEY (COL1)
                  )                  )
 */ */
 </code> </code>
 +
 +
v5/reference/connection/setcustommetatype.1610844176.txt.gz · Last modified: 2021/01/17 01:42 by mnewnham