LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian
User Name
Password
Debian This forum is for the discussion of Debian Linux.

Notices


Reply
  Search this Thread
Old 09-30-2009, 05:03 AM   #1
ts7300
LQ Newbie
 
Registered: Feb 2008
Posts: 17

Rep: Reputation: 0
How to Assign Hex value to Field


Hi,
Below are the Table and I want to assign hex value to field hotter_alert i.e.0xFE.Below I am trying to Modify field attributes.
----------------------------------------------------------
mysql> ALTER TABLE location MODIFY hotter_alert hex();
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'hex()' at line 1
I do not Know whether it's right or wrong.Please let me know how can I give Hex to field Hotter_alert.
+----------------------+---------------+------+-----+------------+----------------+
| Field | Type | Null | Key | Default Extra |
+----------------------+---------------+------+-----+------------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| name | varchar(40) | NO | | | |
| lat | decimal(10,4) | NO | | 0.0000 | |
| lng | decimal(10,4) | NO | | 0.0000 | | |
| hotter_alert | int(10) | YES | | NULL | |
| inserted | date | NO | | 0000-00-00 | |
| updated | date | NO | | 0000-00-00 | |
+----------------------+---------------+------+-----+------------+-------------
 
Old 09-30-2009, 05:35 AM   #2
diilbert
Member
 
Registered: Nov 2003
Location: North of the Border
Distribution: Gentoo & Debian
Posts: 155

Rep: Reputation: 30
Using the column type of integer and inserting something link: insert into test (test) values (0x0a) will work. If you are using phpMyAdmin to insert the data you will need to use straight SQL since the builtin insert function will try inserting the data as text and parse it out.

Reference: http://dev.mysql.com/doc/refman/5.0/...al-values.html

Last edited by diilbert; 09-30-2009 at 05:36 AM. Reason: Added Reference
 
Old 09-30-2009, 06:14 AM   #3
ts7300
LQ Newbie
 
Registered: Feb 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Hi,
Thanks for Reply.....
Its work
mysql> ALTER TABLE location MODIFY hotter_alert varchar(20);
+--------------+
| hotter_alert |
+--------------+
| NULL |
| NULL |
| NULL |
| NULL |
| 0xFE |
+--------------+

And inserting Data using php myadmin.
 
Old 10-03-2009, 02:10 AM   #4
ts7300
LQ Newbie
 
Registered: Feb 2008
Posts: 17

Original Poster
Rep: Reputation: 0
Hi,
I am not big champ. of C.Next thing I am trying to do using these value 0xFE and 0x02 to control the I/O of board using MYSQL C based API at baord side.And using PHP admin to insert the value in MYSQL Database.And hotter_alert | varchar(40) | YES | | NULL | | hotter_alert is the field name and want to control the I/O of board from server side by inserting value.From BOARD side I am able tho fetch hooter_alert field value as row[0] and *PCDR is pointer to which want to assign row[0] value.Problem I am getting is that I am able to fetch the value from Database but Not able to assign properly this value *PCDR register.What I thought Problem is that row[0] value fetching from DATABASE come in string of character as such it's printing right value only when %s is given.And *PCDR is declared as unsigned int.Please suggest me How can I assign row[0] value to *PCDR register,so that I can control I/O from server side.

Code:
#include <stdio.h>
#include <stdlib.h>
#include "mysql.h"
#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include<string.h>

void exiterr(int exitcode)
{
    fprintf( stderr, "%s\n", mysql_error(conn) );
    exit( exitcode );
}
int main(int argc, char **argv)
{
   MYSQL *conn;
   MYSQL_RES *res;
   MYSQL_ROW row;
    uint i = 0;
  char *server = "10.64.21.63";
   char *user = "root";
   char *password = "PASSWORD"; /* set me first */
   char *database = "mysql";
 unsigned char *start;
   volatile unsigned int *PCDR, *PCDDR;
   int fd = open("/dev/mem", O_RDWR);
start = mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0x80840000);
   PCDR = (unsigned int *)(start + 0x08);     // port c data register
   PCDDR = (unsigned int *)(start + 0x18);    // port c direction register

   (!mysql_real_connect(conn, server,
         user, password, database, 0, NULL, 0)) 
        exiterr(1);

    if (mysql_select_db(conn,"location"))
        exiterr(2);

    if (mysql_query(conn,"SELECT hotter_alert from location"))
        exiterr(3);

    if (!(res = mysql_store_result(&mysql)))
        exiterr(4);

    while((row = mysql_fetch_row(res))) {
        for (i=0 ; i < mysql_num_fields(res); i++) 
char * val=row[0]
*PCDDR = 0x01; // Make bit 0 an output Port C bit 0 is connected to the FET
*PCDR = val; // Turn the FET on
 printf("%s\n",row[0]);
    }

    if (!mysql_eof(res))
        exiterr(5);

    mysql_free_result(res);
    mysql_close(&mysql);
   close(fd);
   return 0;
}

Last edited by ts7300; 10-03-2009 at 02:29 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[bash] ASCII to HEX and hex to ascii ////// Programming 17 05-08-2018 09:55 PM
php question, how do I get a return from a field within a field? cherrington Programming 11 04-29-2009 01:27 AM
Hex output of a hex/ascii input string mlewis Programming 35 04-10-2008 12:05 PM
Hex socks Linux - General 4 02-17-2005 12:05 PM
hex? Nox Solaris Linux - Newbie 3 12-07-2002 08:52 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Debian

All times are GMT -5. The time now is 06:05 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration