Re: C api - mysql_list_fields

2008-10-07 Thread Mike Aubury
Basically - so I can display it in the same form as the orginal table..

Or - if you want the longer version
I work with an Opensource project called 'Aubit4GL' (its a clone of 
Informix4GL - which allows you to write really nice screen based database 
oriented programs + reports), see http://sourceforge.net/projects/aubit4gl

Anyway - part of that project is a tool called 'asql' (which is a replacement 
for the Informix 'isql' tool..), this tool is itself written using Aubit4GL.


You can think of asql as an easy to use screen based (ncurses) equivilent of 
the mysql tool..
One of the options is a 'Table Info' - where you get a list of the columns and 
the datatypes etc.
When you create a table with a char(20) - you dont want to see it appear as a 
char(60)!

I have a workaround atm - but its really clunky - I do a separate select for 
each column in the form : SHOW COLUMNS FROM table LIKE 'column' for each 
column returned from mysql_list_fields



BTW - I'll need some help with some of the other displays (indexes, status 
etc) - if anyone fancies lending a hand - we always welcome new volunteers!
(The 'mysql' driver for Aubit4GL could probably do with some attention from 
someone who knows their way around)




On Tuesday 07 October 2008 13:10:18 walter harms wrote:
 Mike Aubury schrieb:
  Excellent - this seems to be the issue - the show create table shows :
 
   mysql show create table a\g
  +---+
 +
 
  | Table | Create
 
  Table
|
  +---+
 +
 
  | a | CREATE TABLE `a` (
 
`blah` char(20) default NULL
  ) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
  +---+---
 
 
  So - its utf8 (which I understand enough about to understand why its
  doing what its doing!)
 
  So - the next question is...
  Is there anyway in code I can find the 'fiddle' factor (1,3,or now
  possibly 4) that I need to use to divide by to get back to the character
  width specified in the CREATE TABLE ?

 why do you want to do that ?
 i would expect that mysql uses wchar_t for char() if utf8 is selected.

 re,
  wh



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: C api - mysql_list_fields

2008-10-07 Thread Mike Aubury
Excellent - this seems to be the issue - the show create table shows : 

 mysql show create table a\g
+---++
| Table | Create 
Table   
|
+---++
| a | CREATE TABLE `a` (
  `blah` char(20) default NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 |
+---+---


So - its utf8 (which I understand enough about to understand why its doing 
what its doing!)

So - the next question is...
Is there anyway in code I can find the 'fiddle' factor (1,3,or now possibly 4) 
that I need to use to divide by to get back to the character width specified 
in the CREATE TABLE ? 








On Tuesday 07 October 2008 12:07:28 Joerg Bruehe wrote:
 Hi Mike, all,

 Mike Aubury wrote:
  I'm probably being a bit stupid - but I'm trying to determine (in code)
  the length of the string in the schema for a given table.
 
  So - for example :
 
 
  create table a (
  blah char(20)
  )
 
 
  I want to return '20', but I'm getting '60' when I use
  mysql_list_fields.. (Always seems to be 3x longer that I'm expecting)...
 
  Am I missing something ? (or should I just divide by 3!!)

 You are missing the distinction between character and byte, which is
 brought to you by the ISO character sets which go far beyond ASCII.

 The moment you allow international characters (US-ASCII + German Umlauts
 + French accented vowels + Spanish cedilla + ... + Chinese + Korean +
 ...) in your data, storing one character may need more than one byte.

 The current encoding (versions 5.0 and 5.1) uses up to 3 bytes per
 character, that is the factor 3 you notice.
 With 6.0, a different encoding may be used, which uses up to 4 bytes per
 character.

 If you know you won't need arbitrary characters, you can use the
 charset (or character set) option in your create statements.


 HTH,
 Jörg

 --
 Joerg Bruehe,  MySQL Build Team,  [EMAIL PROTECTED]   (+49 30) 417 01 487
 Sun Microsystems GmbH,   Sonnenallee 1,   D-85551 Kirchheim-Heimstetten
 Geschaeftsfuehrer: Thomas Schroeder, Wolfgang Engels, Dr. Roland Boemer
 Vorsitzender des Aufsichtsrates: Martin Haering Muenchen: HRB161028



--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



C api - mysql_list_fields

2008-10-06 Thread Mike Aubury
I'm probably being a bit stupid - but I'm trying to determine (in code) the 
length of the string in the schema for a given table.

So - for example : 


create table a (
blah char(20)
)


I want to return '20', but I'm getting '60' when I use mysql_list_fields..
(Always seems to be 3x longer that I'm expecting)...

Am I missing something ? (or should I just divide by 3!!)






Heres an example : 

#include stdio.h
#include stdlib.h
#include mysql.h

MYSQL conn;

int main(int argc,char *argv[]) {
// run with  username port   as arguments
char *tabname=a;
char *db=test1;
char *u;
char *p;
MYSQL_RES *result;
MYSQL_FIELD *field;
if (argc!=3) {
printf(usage : %s  username password\n, argv[0]);exit(2);
}
u=argv[1]; p=argv[2];
mysql_init(conn);
if (!mysql_real_connect(conn, NULL,u,p,db,0,NULL,0) ) {
fprintf(stderr, 
Failed to connect to database: Error: %s\n, 
mysql_error(conn)); 
exit(2);
}

result = mysql_list_fields (conn, tabname, NULL);

field = mysql_fetch_field (result);
printf(Field =%s Type=%d Length=%d\n, field-name, 
field-type, field-length);
}






Thanks in advance...

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Password storage

2007-08-18 Thread Mike Aubury
But you can use it for passwords (ask Unix)...

You can't decode what the original password was, but you can encode the 
password they typed in and check the two hashes match - if they do - the 
chances are that the original passwords match (the odds against are huge!)




On Saturday 18 August 2007 16:19, Mogens Melander wrote:

 MD5() is not an encryption function. The MySQL manual states:


-- 
Mike Aubury

Aubit Computing Ltd is registered in England and Wales, Number: 3112827
Registered Address : Murlain Business Centre, Union Street, Chester, CH1 1QP

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: Birthday format

2007-06-25 Thread Mike Aubury
I might be wrong - but isn't that going to mess up on or around the birthday 
because of leap years ? 

I know its more complex - but something like : 


select year(curdate())-year(1952-06-24)-
 (dayofyear(curdate())dayofyear(1952-06-24)) age;


might work better...



On Monday 25 June 2007 21:07, Mike Blezien wrote:
 thanks, worked prefectly,

 Mike
 - Original Message -
 From: Jerry Schwartz [EMAIL PROTECTED]
 To: 'Mike Blezien' [EMAIL PROTECTED]; 'MySQL List'
 mysql@lists.mysql.com
 Sent: Monday, June 25, 2007 3:01 PM
 Subject: RE: Birthday format

  mysql SELECT FLOOR(54.75);
  +--+
 
  | FLOOR(54.75) |
 
  +--+
 
  |   54 |
 
  +--+
  1 row in set (0.05 sec)
 
  Regards,
 
  Jerry Schwartz
  The Infoshop by Global Information Incorporated
  195 Farmington Ave.
  Farmington, CT 06032
 
  860.674.8796 / FAX: 860.674.8341
 
  www.the-infoshop.com
  www.giiexpress.com
  www.etudes-marche.com
 
  -Original Message-
  From: Mike Blezien [mailto:[EMAIL PROTECTED]
  Sent: Monday, June 25, 2007 2:48 PM
  To: MySQL List
  Subject: Birthday format
 
  Hello,
 
  we have a simple query to calculate someones birthday:
 
  SELECT (TO_DAYS(CURDATE()) - TO_DAYS('1952-10-06')) / 365;
 
  = 54.75
 
 
  Now is there away, using SQL, to remove the .75 without
  rounding off. we just
  want the '54' value. We can do it easy enough with our Perl
  programming, but was
  wondering if this can be accomplished within the actual query itself.
 
  TIA,
 
  Mike(mickalo)Blezien
  ===
  Thunder Rain Internet Publishing
  Providing Internet Solution that Work
  http://www.thunder-rain.com
  ===
 
  --
  MySQL General Mailing List
  For list archives: http://lists.mysql.com/mysql
  To unsubscribe:
  http://lists.mysql.com/[EMAIL PROTECTED]

-- 
Mike Aubury

Aubit Computing Ltd is registered in England and Wales, Number: 3112827
Registered Address : Murlain Business Centre, Union Street, Chester, CH1 1QP

-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: simple alternate query

2007-01-29 Thread Mike Aubury
Be careful there...
You should probably use '(' ')' around that ...


select * from table1 where id=1 or (id=3 and id=4) 

 
On Sunday 28 January 2007 02:21, Miguel Vaz wrote:
  I am dumb, so sorry:

  select * from table1 where id=1 or id =3 and id =4

  Have to go spank myself until i bleed now, thanks.





  Miguel

 At 02:15 28-01-2007, Miguel Vaz wrote:
  Hi,
 
  I Cant get a simple query to work, heres what i am looking for:
 
  table1
  --
  id  name
  1   peter
  2   john
  3   mary
  4   lisa
  5   me
 
  I need a select that always retrieves id 1 and an interval
  of my choice:

-- 
Mike Aubury


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



C API blobs

2006-12-08 Thread Mike Aubury
Can anyone point me in the direction of some examples of using the 
libmysqclient API for reading/writing blobs ? 

I'm currently reading the data from some dynamic SQL using 
mysql_stmt_bind_result  mysql_stmt_fetch - and want to add the BLOB 
datatypes

TIA

-- 
Mike Aubury


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: undefined reference to 'mysql_init'

2006-07-23 Thread Mike Aubury
Try 
gcc -o test test.c  -lmysqlclient


On Sunday 23 July 2006 13:14, ali asghar torabi parizy wrote:
 Hi,
I am begeener  to MySQL. I have installed Suse10 and MySQL and mysql++ 
 in my pc.

  i want to connect to MySQL through C. When I am compiling the program,
   I am getting the following error.
  ***
  gcc -o test test.c
  test.c:28:3: warning: no newline at end of file
  /tmp/cchl7IEh.o: In function `main':
  test.c:(.text+0x22): undefined reference to `mysql_init'
  test.c:(.text+0x4f): undefined reference to `mysql_real_connect'
  test.c:(.text+0x65): undefined reference to `mysql_query'
  test.c:(.text+0x76): undefined reference to `mysql_store_result'
  test.c:(.text+0x87): undefined reference to `mysql_num_rows'
  test.c:(.text+0xdc): undefined reference to `ltmysql_num_fields'
  test.c:(.text+0xf1): undefined reference to `mysql_fetch_row'
  test.c:(.text+0x10b): undefined reference to `mysql_close'
  collect2: ld returned 1 exit status
  ***
  The code is as fillows:
  ***

 #include stdio.h  #include mysql.h  #define host localhost  #define
 username mysql  #define password   #define database test MYSQL *conn;
 int main()  {  conn = mysql_init(NULL);
 mysql_real_connect(conn,host,username,password,database,0,NULL,0);
 MYSQL_RES *res_set;  MYSQL_ROW row;  unsigned int i; 
 mysql_query(conn,SELECT * FROM users WHERE userid=1); res_set =
 mysql_store_result(conn); unsigned int numrows = mysql_num_rows(res_set);
 while ((row = mysql_fetch_row(res_set)) != NULL)  { for (i=0;
 iltmysql_num_fields(res_set); i++)  {  printf(%s\n,row[i] != NULL ?
 row[i] : NULL); }  }  mysql_close(conn);  return 0;  }
 *
 Please help me in this regard.




 -
 Yahoo! Messenger with Voice. Make PC-to-Phone Calls to the US (and 30+
 countries) for 2¢/min or less.

-- 
Mike Aubury


--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Anyone interested in a 4gl compiler ?

2006-07-21 Thread Mike Aubury
Hi there,
I'm the lead developer on Aubit4GL (http://aubit4gl.sourceforge.net) which is 
a 4gl compiler used for writing database centric applications based on the 
original Informix-4GL language..

I'm just wondering what the appetite is like out there for a mysql compatible 
version (we've got a very simple mysql connector already, as well as 
postgres,  ODBC).



-- 
Mike Aubury


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]



Re: quickie for a non-blonde!

2006-07-13 Thread Mike Aubury
Assuming that the lastest ID is the same as the current name - maybe something 
like : 

select * from sometab t1 
where id=(
select max(id) from sometab t2 where t1.code=t2.code
)


On Thursday 13 July 2006 10:16, Helen M Hudson wrote:
 If I have a table
 primary key id   |  code| name
 1   |  ABC   | company 1 name
 2   |  ABC   | company 1 name
 3   |  ABC   | new company 1 name
 4   |  ABC   | new company 1 name
 5   |  DEF| company 2 name
 6   |  DEF| company 2 name
 7   |  DEF| new company 2 name
 8   |  DEF| new company 2 name

 (the company is changing name every now and then and i need to extract
 their latest name)

 how can i get back
 4   |  ABC   | new company 1 name
 8   |  DEF| new company 2 name

-- 
Mike Aubury


-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]