[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mysql-odbc
Subject:    bk commit - MyODBC 3.51
From:       venu () mysql ! com
Date:       2002-10-11 11:54:16
[Download RAW message or body]

Below is the list of changes that have just been commited into a local
MyODBC 3.51 repository of 'venu'. When 'venu' does a push, they will be
propogaged to the main repository and within 24 hours after the push
into the public repository. 

For more information on how to access the public repository see
http://www.mysql.com/products/myodbc/faq.html#Development_source

ChangeSet
  1.222 02/10/11 01:07:18 venu@myvenu.com +1 -0
  Missed one from previous commit

  catalog.c
    1.20 02/10/11 01:06:19 venu@myvenu.com +155 -70

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	venu
# Host:	myvenu.com
# Root:	/home/venu/work/odbc/dev-3.51

--- 1.19/catalog.c	Sun Sep 29 09:03:48 2002
+++ 1.20/catalog.c	Fri Oct 11 01:06:19 2002
@@ -54,8 +54,11 @@
 			    bool no_wildcards);

 static void my_append_wild(char *to, char *end, const char *wild);
+const char *get_reference_token(const char *prev_token, char **token, 
+                                char *data, const char chr);
 
 uint SQLTABLES_order[]={2};
+uint SQLTABLES_qualifier_order[]={0};
 char *SQLTABLES_sysvalues[]={"","",NULL,"SYSTEM TABLE","MySQL System
Table"};  char *SQLTABLES_values[]={"","",NULL,"TABLE","MySQL table"};
char *SQLTABLES_qualifier_values[]={"",NULL,NULL,NULL,NULL};
@@ -71,16 +74,23 @@
 
 const uint SQLTABLES_FIELDS=array_elements(SQLTABLES_values);
 
+#ifdef __WIN__
+#define cmp_database(A,B) _casecmp((A),(B),strlen(B))
+#else
+#define cmp_database(A,B) strcmp((A),(B))
+#endif
+
+
 /*
   @type    : internal
-  @purpose : returns system tables
+  @purpose : returns tables from a perticular database
 */
-static MYSQL_RES *mysql_list_sys_tables(MYSQL *mysql, const char
*table) -{
-  char buff[255]; 
+static MYSQL_RES *mysql_list_dbtables(MYSQL *mysql, const char *db,
+                                      const char *table) {
+  char buff[255];
 
-  my_append_wild(strmov(buff,"show tables from `mysql`"),
-                 buff+sizeof(buff)-1,table);
+  strxmov(buff,"SHOW TABLES FROM `",db,"`",NullS);
+ my_append_wild(strmov(buff,buff),buff+sizeof(buff)-1,table);
   if (mysql_query(mysql,buff))
     return 0;
   return mysql_store_result(mysql);
@@ -142,6 +152,7 @@
   char
Qualifier_buff[NAME_LEN+1],Owner_buff[NAME_LEN+1],Name_buff[NAME_LEN+1],
        *type_buff,*TableQualifier,*TableOwner,*TableName,*TableType;
   STMT FAR *stmt=(STMT FAR*) hstmt;
+  my_bool all_dbs = 1;
   DBUG_ENTER("SQLTables");
   DBUG_PRINT("enter",("Qualifier: '%s'  Owner: '%s'  Table: '%s'  Type:
'%s'",
 		      szTableQualifier ? (char*) szTableQualifier :
"null", @@ -150,33 +161,41 @@
 		      szTableType ? (char*) szTableType : "null"));
 
   my_SQLFreeStmt(hstmt,MYSQL_RESET);
-  if (!(type_buff=my_malloc(szTableType && cbTableType != SQL_NTS ?
-			    cbTableType+1 : 1,MYF(0))))
-  {
-    DBUG_RETURN(set_error(stmt,MYERR_S1001,NULL,0));
-  }
 
   TableQualifier=fix_str((char FAR *) Qualifier_buff,szTableQualifier,
 			 cbTableQualifier);
   TableOwner=	 fix_str((char FAR*)
Owner_buff,szTableOwner,cbTableOwner);
   TableName=	 fix_str((char FAR*) Name_buff,szTableName,cbTableName);
-  TableType=	 fix_str((char FAR*) type_buff,szTableType,cbTableType);
 
-  if (!strcmp(TableQualifier,"%") && !TableOwner[0] && !TableName[0])
+  if ((!strcmp(TableQualifier,"%") ||
+       !(all_dbs= _casecmp(TableQualifier,"SQL_ALL_CATALOGS",16))) &&
+      !TableOwner[0] && !TableName[0])
   {
     /* Return set of allowed qualifiers */
     DBUG_PRINT("info",("Return set of table qualifiers / Catalog
names"));
-    stmt->result=(MYSQL_RES*)
my_malloc(sizeof(MYSQL_RES),MYF(MY_ZEROFILL));
-    stmt->result_array=(MYSQL_ROW) my_memdup((gptr)
SQLTABLES_qualifier_values,
-
sizeof(SQLTABLES_qualifier_values),
-					    MYF(0));
-    stmt->result->row_count=1;
-    mysql_link_fields(stmt,SQLTABLES_fields, SQLTABLES_FIELDS);
-    my_free(type_buff,MYF(0));
+    
+    if (!all_dbs)
+      TableQualifier="%";
+    
+    pthread_mutex_lock(&stmt->dbc->lock);
+    stmt->result=mysql_list_dbs(&stmt->dbc->mysql,TableQualifier);
+    pthread_mutex_unlock(&stmt->dbc->lock);
+
+    if (!stmt->result)
+      goto empty_set;
+              
+    stmt->order         =	SQLTABLES_qualifier_order;
+    stmt->order_count   = array_elements(SQLTABLES_qualifier_order);
+    stmt->fix_fields    = fix_fields_copy;
+    stmt->array=(MYSQL_ROW) my_memdup((gptr)
SQLTABLES_qualifier_values,
+
sizeof(SQLTABLES_qualifier_values),MYF(0));
+    mysql_link_fields(stmt,SQLTABLES_fields,SQLTABLES_FIELDS);
     DBUG_RETURN_STATUS(SQL_SUCCESS);
   }
 
-  if (!TableQualifier[0] && !strcmp(TableOwner,"%") && !TableName[0])
+  if (!TableQualifier[0] && (!strcmp(TableOwner,"%") ||
+      !_casecmp(TableOwner,"SQL_ALL_SCHEMAS",15)) && 
+      !TableName[0])
   {
     /* Return set of allowed Table owners */
     DBUG_PRINT("info",("Return set of table owners / Schema names"));
@@ -186,12 +205,20 @@
 					      MYF(0));
     stmt->result->row_count=1;
     mysql_link_fields(stmt,SQLTABLES_fields, SQLTABLES_FIELDS);
-    my_free(type_buff,MYF(0));
     DBUG_RETURN_STATUS(SQL_SUCCESS);
   }
 
+  if (!(type_buff=my_malloc(szTableType && cbTableType != SQL_NTS ?
+			    cbTableType+1 : 1,MYF(0))))
+  {
+    DBUG_RETURN(set_error(stmt,MYERR_S1001,NULL,0));
+  }
+
+  TableType=	 fix_str((char FAR*) type_buff,szTableType,cbTableType);
+
   if (!TableQualifier[0] && !TableOwner[0] && !TableName[0] &&
-      !strcmp(TableType,"%"))
+      (!strcmp(TableType,"%") ||
+       !_casecmp(TableType,"SQL_ALL_TABLE_TYPES",19)))   
   {
     /* Return set of TableType qualifiers */
     DBUG_PRINT("info",("Return set of table types"));
@@ -208,30 +235,32 @@
   /* Return empty set if unknown TableType or if Qualifier or Owner is
used */
   if ((TableType[0] && !user_tables(TableType)) ||
       TableQualifier[0] && strcmp(TableQualifier,"%") &&
-      strcmp(TableQualifier,stmt->dbc->database) ||
       TableOwner[0] && strcmp(TableOwner,"%") &&
       strcmp(TableOwner,stmt->dbc->database))
+    goto empty_set;
+
+  if (szTableQualifier && 
+      cmp_database(stmt->dbc->mysql.db, TableQualifier))
   {
-    DBUG_PRINT("info",("Can't match anything; Returning empty set"));
-    stmt->result=(MYSQL_RES*)
my_malloc(sizeof(MYSQL_RES),MYF(MY_ZEROFILL));
-    stmt->result->row_count=0;
-    stmt->result_array=(MYSQL_ROW) my_memdup((gptr) SQLTABLES_values,
-					    sizeof(SQLTABLES_values),
MYF(0));
-    mysql_link_fields(stmt,SQLTABLES_fields, SQLTABLES_FIELDS);
-    my_free(type_buff,MYF(0));    
-    DBUG_RETURN_STATUS(SQL_SUCCESS);
+    /* Return tables from a perticular database */
+    DBUG_PRINT("info",("Return set of tables '%s' from '%s'",TableName,
TableQualifier));
+    pthread_mutex_lock(&stmt->dbc->lock);                         
+    stmt->result=mysql_list_dbtables(&stmt->dbc->mysql,
+                                     TableQualifier,TableName);     
+    pthread_mutex_unlock(&stmt->dbc->lock);
   }
-
-  pthread_mutex_lock(&stmt->dbc->lock);
-  stmt->result=mysql_list_tables(&stmt->dbc->mysql,TableName);
-  pthread_mutex_unlock(&stmt->dbc->lock);
-  
-  if (!stmt->result)
+  else
   {
-    my_free(type_buff,MYF(0));
-    DBUG_RETURN(set_error(stmt,MYERR_S1000,"Could not read table
names",0));
+    /* Return tables from default/current database */    
+    DBUG_PRINT("info",("Returning set of current database tables
'%s'",TableName));
+    pthread_mutex_lock(&stmt->dbc->lock);
+    stmt->result=mysql_list_tables(&stmt->dbc->mysql,TableName);
+    pthread_mutex_unlock(&stmt->dbc->lock);
   }
-  SQLTABLES_values[0] = stmt->dbc->mysql.db;
+  if (!stmt->result)
+    goto empty_set;
+  
+  SQLTABLES_values[0] = TableQualifier;
   stmt->order         =	SQLTABLES_order;
   stmt->order_count   = array_elements(SQLTABLES_order);
   stmt->fix_fields    = fix_fields_copy;
@@ -246,6 +275,16 @@
   mysql_link_fields(stmt,SQLTABLES_fields,5);
   my_free(type_buff,MYF(0));  
   DBUG_RETURN_STATUS(SQL_SUCCESS);
+  
+empty_set:
+  DBUG_PRINT("info",("Can't match anything; Returning empty set"));
+  stmt->result=(MYSQL_RES*)
+my_malloc(sizeof(MYSQL_RES),MYF(MY_ZEROFILL));
+  stmt->result->row_count=0;
+  stmt->result_array=(MYSQL_ROW) my_memdup((gptr) SQLTABLES_values,
+			    sizeof(SQLTABLES_values), MYF(0));
+  mysql_link_fields(stmt,SQLTABLES_fields, SQLTABLES_FIELDS);
+  my_free(type_buff,MYF(0));
+  DBUG_RETURN_STATUS(SQL_SUCCESS);
 }
 
 
@@ -543,6 +582,7 @@
     buff+sizeof(buff),table);
   strxmov(buff,buff," AND Db",NullS);
   my_append_wild(strmov(buff,buff),buff+sizeof(buff),qualifier);
+  strxmov(buff,buff," ORDER BY Db,Table_name,Table_priv,User",NullS);
 
   if (mysql_query(mysql,buff))
     DBUG_RETURN(0);
@@ -556,7 +596,8 @@
 char *SQLTABLES_priv_values[]= {
   NULL,"",NULL,NULL,NULL,NULL,NULL
 };
-
+#define MY_MAX_TABPRIV_COUNT 21
+#define MY_MAX_COLPRIV_COUNT 3
 MYSQL_FIELD SQLTABLES_priv_fields[] = {
   {"TABLE_CAT","MySQL_Catalog",NULL,FIELD_TYPE_VAR_STRING,NAME_LEN,0},
 
{"TABLE_SCHEM","MySQL_Catalog",NULL,FIELD_TYPE_VAR_STRING,NAME_LEN,0},
@@ -588,7 +629,9 @@
   char Qualifier_buff[NAME_LEN+1],Name_buff[NAME_LEN+1],
        *TableQualifier,*TableName;
   char **row;
+  MEM_ROOT *alloc;
   STMT FAR *stmt=(STMT FAR*) hstmt;
+  uint row_count=0;
   DBUG_ENTER("SQLTablePrivileges");
   DBUG_PRINT("enter",("Qualifier: '%s'  Owner: '%s'  Table: '%s'",
           szTableQualifier ? (char*) szTableQualifier : "null", @@
-610,20 +653,40 @@
     DBUG_RETURN_STATUS(SQL_ERROR);
   }
   pthread_mutex_unlock(&stmt->dbc->lock);
-  stmt->result_array= (char**)
my_malloc(sizeof(char*)*SQLTABLES_PRIV_FIELDS*
-         (ulong) stmt->result->row_count, MYF(MY_FAE | MY_ZEROFILL));
-  data=stmt->result_array;
+  /* Allocate max buffers, to avoid reallocation */
+ stmt->result_array= (char**) my_malloc(sizeof(char*)* 
+ stmt->SQLTABLES_PRIV_FIELDS *
+                                        stmt->result->row_count *
MY_MAX_TABPRIV_COUNT, 
+                                        MYF(MY_FAE | MY_ZEROFILL));
+ alloc= &stmt->result->field_alloc;  data= stmt->result_array;
   while ((row = mysql_fetch_row(stmt->result)))
-  { 
-    data[0]=row[0];         
-    data[1]="";         
-    data[2]=row[2];
-    data[3]=row[3];   
-    data[4]=row[1];
-    data[5]=row[4];
-    data[6]=is_grantable(row[4]) ? "YES":"NO";
-    data+=SQLTABLES_PRIV_FIELDS;
-  }
+  {     
+    char  *grants = row[4];
+    char  token[NAME_LEN+1];
+    const char *grant = (const char *)grants;
+        
+    for(;;)
+    {
+      data[0]=row[0];         
+      data[1]="";         
+      data[2]=row[2];
+      data[3]=row[3];   
+      data[4]=row[1];
+      data[6]=is_grantable(row[4]) ? "YES":"NO";    
+      row_count++;
+    
+      if (!(grant= get_reference_token(grant,&grants,token,',')))
+      {
+        /* End of grants .. */
+        data[5]= strdup_root(alloc,grants);
+        data+= SQLTABLES_PRIV_FIELDS; 
+        break;
+      }      
+      data[5]= strdup_root(alloc,token);    
+      data+= SQLTABLES_PRIV_FIELDS;      
+    }
+  }
+  stmt->result->row_count=row_count;
   mysql_link_fields(stmt,SQLTABLES_priv_fields,SQLTABLES_PRIV_FIELDS);
   DBUG_RETURN_STATUS(SQL_SUCCESS);
 }
@@ -650,7 +713,8 @@
   my_append_wild(strmov(buff,buff),buff+sizeof(buff),qualifier);
   strxmov(buff,buff," AND c.Column_name",NullS);
   my_append_wild(strmov(buff,buff),buff+sizeof(buff),column);
-  strxmov(buff,buff," AND c.Table_name=t.Table_name",NullS);
+  strxmov(buff,buff," AND c.Table_name=t.Table_name",
+          " ORDER BY c.Db,c.Table_name,c.Column_name,c.Column_priv",
+ NullS);
   
   if (mysql_query(mysql,buff))
     DBUG_RETURN(0);
@@ -699,7 +763,9 @@
   char Qualifier_buff[NAME_LEN+1],Table_buff[NAME_LEN+1],
        Column_buff[NAME_LEN+1],
        *TableQualifier,*TableName, *ColumnName;
-  char **row, **data;  
+  char **row, **data;
+  MEM_ROOT *alloc;
+  uint row_count=0;
   DBUG_ENTER("SQLColumnPrivileges");
   DBUG_PRINT("enter",("Qualifier: '%s'  Owner: '%s'  Table: '%s'
column: '%s'",
           szTableQualifier ? (char*) szTableQualifier : "null", @@
-724,20 +790,38 @@
   }
   pthread_mutex_unlock(&stmt->dbc->lock);
   stmt->result_array= (char**)
my_malloc(sizeof(char*)*SQLCOLUMNS_PRIV_FIELDS*
-         (ulong) stmt->result->row_count, MYF(MY_FAE | MY_ZEROFILL));
-  data=stmt->result_array;
+         (ulong) stmt->result->row_count *MY_MAX_COLPRIV_COUNT,
+ MYF(MY_FAE | MY_ZEROFILL));  alloc= &stmt->result->field_alloc;  data=

+ stmt->result_array;
   while ((row = mysql_fetch_row(stmt->result)))
-  { 
-    data[0]=row[0];         
-    data[1]="";         
-    data[2]=row[2];
-    data[3]=row[3];
-    data[4]=row[4];
-    data[5]=row[1];
-    data[6]=row[5];
-    data[7]=is_grantable(row[6]) ? "YES":"NO";
-    data+=SQLCOLUMNS_PRIV_FIELDS;
-  }  
+  {
+    char  *grants = row[5];
+    char  token[NAME_LEN+1];
+    const char *grant = (const char *)grants;
+
+    for(;;)
+    {
+      data[0]=row[0];
+      data[1]="";
+      data[2]=row[2];
+      data[3]=row[3];
+      data[4]=row[4];
+      data[5]=row[1];
+      data[7]=is_grantable(row[6]) ? "YES":"NO";
+      row_count++;
+
+      if (!(grant= get_reference_token(grant,&grants,token,',')))
+      {
+        /* End of grants .. */
+        data[6]= strdup_root(alloc,grants);
+        data+= SQLCOLUMNS_PRIV_FIELDS;
+        break;
+      }
+      data[6]= strdup_root(alloc,token);
+      data+= SQLCOLUMNS_PRIV_FIELDS;
+    }
+  }
+  stmt->result->row_count=row_count;
 
mysql_link_fields(stmt,SQLCOLUMNS_priv_fields,SQLCOLUMNS_PRIV_FIELDS);
   DBUG_RETURN_STATUS(SQL_SUCCESS); 
 }
@@ -794,6 +878,7 @@
 		      fColType,
           szTableQualifier ? (char*) szTableQualifier : "null",
 		      szTableOwner ? (char*) szTableOwner : "null",
+          szTableName ? (char*) szTableName : "null",
 		      fScope, fNullable));
 
   if
(check_parameters(hstmt,szTableQualifier,cbTableQualifier,szTableOwner,



---------------------------------------------------------------------
Please check "http://www.mysql.com/Manual_chapter/manual_toc.html" before
posting. To request this thread, e-mail myodbc-thread6210@lists.mysql.com

To unsubscribe, send a message to the address shown in the
List-Unsubscribe header of this message. If you cannot see it,
e-mail myodbc-unsubscribe@lists.mysql.com instead.

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic