error: too many arguments to function `mysql_query'

Please support our C advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Jul 2006
Posts: 32
Reputation: whitemoss is an unknown quantity at this point 
Solved Threads: 0
whitemoss whitemoss is offline Offline
Light Poster

error: too many arguments to function `mysql_query'

 
0
  #1
Nov 13th, 2006
Hi all,

I try to compile my program and got this kind of error:
test6.c: In function `main':
test6.c:46: too many arguments to function `mysql_query'

Here is my code:

  1. int main(int argc, char *argv[])
  2. {
  3.  
  4. char string1[1600], string2[1600], query[1600], mobileno[50];
  5. int i, j, len;
  6. FILE *fp2;
  7.  
  8.  
  9. mysql_init(&conn);
  10.  
  11. /* Connect to database */
  12. if (!mysql_real_connect(&conn, host, user, password, database, 0, NULL, 0)) {
  13. fprintf(stderr, "%s\n", mysql_error(&conn));
  14. exit(0);
  15. }
  16.  
  17.  
  18. /* send SQL query */
  19. if (mysql_query(&conn, "select a.MobileNumber, a.MasterNumber , a.MasterAccNo, b.Addr, b.Addr2, b.Addr3, b.Addr4, b.Addr5, b.Addr6, b.Addr7, b.Addr8, b.Postcode, b.CountryCode, b.BillName, b.CorrName, b.ICNew, b.ICOld, b.Passport from Register as a, Profile as b where a.MasterNumber = b.Number and a.Status=0 and a.MasterNumber = '%s'", masterno)) {
  20. fprintf(stderr, "%s\n", mysql_error(&conn));
  21. exit(0);
  22. }
  23.  
  24. res = mysql_use_result(&conn);
  25.  
  26.  
  27. /* output fields 0, 1 and 2 of each row */
  28. while ((row = mysql_fetch_row(res)) != NULL)
  29. {
  30. if (i==11)
  31. {
  32. timebuffer();
  33. i=1;
  34. bzero(string1, sizeof(string1));
  35. }
  36. else
  37. {
  38. sprintf(string1,"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|", row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18]);
  39. printf ("%s\n",string1);
  40.  
  41.  
  42. writeLogFile(string1, mobileno);
  43. i++;
  44. }
  45. }
  46.  
  47. /* Release memory used to store results and close connection */
  48. mysql_free_result(res);
  49. mysql_close(&conn);
  50.  
  51. return 0;
  52. }

i try to alter the code to become like this:
  1. /* send SQL query */
  2.  
  3. bzero(query1, sizeof(query1));
  4. sprintf(query1, "select a.MobileNumber, a.MasterNumber , a.MasterAccNo, b.Addr, b.Addr2, b.Addr3, b.Addr4, b.Addr5, b.Addr6, b.Addr7, b.Addr8, b.Postcode, b.CountryCode, b.BillName, b.CorrName, b.ICNew, b.ICOld, b.Passport from Register as a, Profile as b where a.MasterNumber = b.Number and a.MasterNumber = '%s' and a.Status=0", MasterNo);
  5. printf ("%s\n",query1);
  6.  
  7. if (mysql_query(&conn, query1))
  8. {
  9. fprintf(stderr, "%s\n", mysql_error(&conn));
  10. exit(0);
  11. }

at the end..when i try to run the program, i got "segmentation fault"

Please help me..many thanks
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 275
Reputation: andor has a spectacular aura about andor has a spectacular aura about andor has a spectacular aura about 
Solved Threads: 29
andor's Avatar
andor andor is offline Offline
Posting Whiz in Training

Re: error: too many arguments to function `mysql_query'

 
0
  #2
Nov 13th, 2006
You cant do this
  1. foo(someParam, "my age is %d", age)
becouse the compiler thinks the function takes 3 parametars but at his definition it takes two.
Last edited by andor; Nov 13th, 2006 at 6:38 am.
If you want to win, you must not loose (Alan Ford)
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error: too many arguments to function `mysql_query'

 
0
  #3
Nov 13th, 2006
For your own santity why don't you break up that HUGE string into several lines to make it easier for you to read. Example: Note that each line starts and ends with quotes and does not have a line terminator semicolon.

  1. sprintf(query1, "select a.MobileNumber, a.MasterNumber ,"
  2. "a.MasterAccNo, b.Addr, b.Addr2, b.Addr3, b.Addr4, b.Addr5, b.Addr6,"
  3. "b.Addr7, b.Addr8, b.Postcode, b.CountryCode, b.BillName, b.CorrName,"
  4. "b.ICNew, b.ICOld, b.Passport from Register as a, Profile as b"
  5. " where a.MasterNumber = b.Number and a.MasterNumber = '%s' and"
  6. " a.Status=0", MasterNo);
Last edited by Ancient Dragon; Nov 13th, 2006 at 7:29 am.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 32
Reputation: whitemoss is an unknown quantity at this point 
Solved Threads: 0
whitemoss whitemoss is offline Offline
Light Poster

Re: error: too many arguments to function `mysql_query'

 
0
  #4
Nov 13th, 2006
Hi all,

Thanks for ur reply....the above problem has been solved...

i have another thing..hopefully u all can help me. as u all can see, i have written a writeLogFile function where it appends the data select from db to a file namely data.txt...but i would like to change it so that, i dont need to specify the filename..instead, this function can appends the data into a different file based on when the data was appended. Actually i have created a cron job to run this program by hourly so..the filename should be on hourly basis..For example at 10 am on 14/11/2006...this program is running and it appends the data from database to a file namely data-10-14-11-2006.txt...1 hr later, it appends another data to other file namely data-11-14-11-2006.txt and so on... how to expand this function so that it can cater as what i've mentioned before..

below is the code for writeLogFile function:

  1. void writeLogFile(char line2[1600], char* MobileNo)
  2. {
  3.  
  4. FILE *fp;
  5.  
  6. fp=fopen("data.txt", "a+");
  7. if ( (fputs(line2, fp)) == EOF) {
  8. printf("error write...");
  9. }
  10. if ( (fputs("\n", fp)) == EOF) {
  11. printf("error write1...");
  12. }
  13. fclose(fp);
  14.  
  15. }

ur help is very much appreciated...Many thanks
Last edited by whitemoss; Nov 13th, 2006 at 12:30 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error: too many arguments to function `mysql_query'

 
0
  #5
Nov 13th, 2006
I have a logging program that changes the filename every day. Whenever the log function is called it creates the filename based on the current system time. Example:
  1. char filename[255];
  2. time_t now = time(0);
  3. struct tm* tm = localtime(&now);
  4. sprintf(filename,"%02d-02d-04d.txt", tm->tm_day, <snip> ...);
Last edited by Ancient Dragon; Nov 13th, 2006 at 1:08 pm.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 32
Reputation: whitemoss is an unknown quantity at this point 
Solved Threads: 0
whitemoss whitemoss is offline Offline
Light Poster

Re: error: too many arguments to function `mysql_query'

 
0
  #6
Nov 17th, 2006
Hi all..

I've written a code something like this:
  1. void get_year(char* year)
  2. {
  3. strcpy(year, Year);
  4. }
  5.  
  6. void get_month(char* month)
  7. {
  8. strcpy(month, Month);
  9. }
  10.  
  11. void get_day(char* day)
  12. {
  13. strcpy(day, Day);
  14. }
  15.  
  16. void set_year(struct tm* tb)
  17.  
  18. {
  19. memset(Year, '\0', sizeof(Year));
  20.  
  21. strftime(Year, sizeof(Year), "%Y", tb);
  22. iYear = atoi(Year);
  23. }
  24.  
  25. void set_day(struct tm* tb)
  26. {
  27. iDay = tb->tm_mday;
  28. strftime(Day, sizeof(Day), "%a", tb);
  29. }
  30.  
  31. void set_month(struct tm* tb)
  32.  
  33. {
  34. iMonth = tb->tm_mon + 1;
  35. memset(Month, '\0', sizeof(Month));
  36. strftime(Month, sizeof(Month), "%b", tb);
  37. }
  38.  
  39. void set_systime()
  40. {
  41. /* gets time of day */
  42. now = time(NULL);
  43.  
  44. /* converts date/time to a structure */
  45. struct tm* tb = localtime(&now);
  46.  
  47. set_day(now);
  48. set_month(now);
  49. set_year(now);
  50. }
  51.  
  52. void writeLogFile(char line2[1600], char* MobileNo)
  53. {
  54. char Temp[55];
  55. char Year[5];
  56. char filename[255], HourlyFileName[500];
  57.  
  58. memset(filename, '\0', sizeof(filename));
  59.  
  60. sprintf (filename, "%02d-%02d-%04s.log",
  61. pTime->get_day(),
  62. pTime->get_month(),
  63. pTime->get_Year());
  64.  
  65. FILE *fp;
  66.  
  67.  
  68. fp=fopen(filename, "a+");
  69.  
  70. if ( (fputs(line2, fp)) == EOF)
  71. {
  72. printf("error write...");
  73. }
  74. if ( (fputs("\n", fp)) == EOF)
  75. {
  76. printf("error write1...");
  77. }
  78.  
  79. fclose(fp);
  80.  
  81. printf ("%s\n",filename);
  82. }
i try to compile this error but i've got this message..dunno how to solve it

  1. test8.c: In function `set_year':
  2. test8.c:140: incompatible types in assignment
  3. test8.c: In function `set_day':
  4. test8.c:145: incompatible types in assignment
  5. test8.c: In function `set_month':
  6. test8.c:152: incompatible types in assignment
  7. test8.c: In function `set_systime':
  8. test8.c:162: incompatible types in assignment
  9. test8.c:165: warning: passing arg 1 of `localtime' from incompatible pointer type
  10. test8.c: In function `writeLogFile':
  11. test8.c:219: dereferencing pointer to incomplete type
  12. test8.c:220: dereferencing pointer to incomplete type
  13. test8.c:221: dereferencing pointer to incomplete type
hopefully anyone can help me..thanks
Last edited by whitemoss; Nov 17th, 2006 at 4:07 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,996
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 308
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Cenosillicaphobiac

Re: error: too many arguments to function `mysql_query'

 
0
  #7
Nov 17th, 2006
Is this a new question?
Originally Posted by whitemoss
void set_day(struct tm* tb)
{
iDay = tb->tm_mday;
strftime(Day, sizeof(Day), "%a", tb);
}
Well, there's a problem in here, but I can't tell what. Where is iDay declared? Please post your entire (or relevant) code.

regards Niek
Last edited by niek_e; Nov 17th, 2006 at 4:51 am. Reason: Wasn't reading
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 32
Reputation: whitemoss is an unknown quantity at this point 
Solved Threads: 0
whitemoss whitemoss is offline Offline
Light Poster

Re: error: too many arguments to function `mysql_query'

 
0
  #8
Nov 20th, 2006
Hi all,

i've changed my code and it's more simpler than before..I already can compile the code but then, when i'm trying to run it, i've got the "Segmentation Fault" error.

The code is as below:

  1. #include <mysql.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <stdlib.h>
  5. #include <time.h>
  6.  
  7. MYSQL conn;
  8. MYSQL_RES *res;
  9. MYSQL_ROW row;
  10.  
  11. char *host = "localhost";
  12. char *user = "External";
  13. char *password = "prepaidsms";
  14. char *database = "External";
  15.  
  16. int tbuf;
  17. char* buf;
  18. char *line;
  19. char MasterNo[50];
  20.  
  21. void writeLogFile(char line2[1600], char* MobileNo);
  22. void UpdateStatus(char* MobileNo);
  23. void timebuffer();
  24.  
  25.  
  26. int main(int argc, char *argv[])
  27. {
  28.  
  29. char string1[1600], string2[1600], query[1600], query1[1600], mobileno[50];
  30. int i, j, len;
  31. FILE *fp2;
  32.  
  33.  
  34. mysql_init(&conn);
  35.  
  36. /* Connect to database */
  37. if (!mysql_real_connect(&conn, host, user, password, database, 0, NULL, 0)) {
  38. fprintf(stderr, "%s\n", mysql_error(&conn));
  39. exit(0);
  40. }
  41.  
  42. /* send SQL query */
  43.  
  44. bzero(query1, sizeof(query1));
  45. sprintf(query1, "select a.MobileNumber, a.MasterNumber, a.MasterAccNo, b.Addr, b.Addr2, b.Addr3, b.Addr4, b.Addr5, b.Addr6,"
  46. "b.Addr7, b.Addr8, b.Postcode, b.CountryCode, b.BillName, b.CorrName, b.ICNew, b.ICOld, b.Passport from Register as a, Profile as b"
  47. " where a.MasterNumber = b.Number and a.Status=0");
  48.  
  49. //printf ("%s\n",query1);
  50.  
  51. if (mysql_query(&conn, query1))
  52. {
  53. fprintf(stderr, "%s\n", mysql_error(&conn));
  54. exit(0);
  55. }
  56.  
  57.  
  58. res = mysql_use_result(&conn);
  59.  
  60.  
  61. /* output fields 0, 1 and 2 of each row */
  62. while ((row = mysql_fetch_row(res)) != NULL)
  63. {
  64. if (i==11)
  65. {
  66. timebuffer();
  67. i=1;
  68. bzero(string1, sizeof(string1));
  69. }
  70. else
  71. {
  72. sprintf(string1,"%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|%s|",
  73. row[0], row[1], row[2], row[3], row[4], row[5], row[6], row[7], row[8], row[9], row[10], row[11], row[12], row[13], row[14], row[15], row[16], row[17], row[18]);
  74. printf ("%s\n",string1);
  75.  
  76.  
  77. writeLogFile(string1, mobileno);
  78. i++;
  79. }
  80. }
  81.  
  82. /* Release memory used to store results and close connection */
  83. mysql_free_result(res);
  84. mysql_close(&conn);
  85.  
  86. return 0;
  87. }
  88.  
  89. void writeLogFile(char line2[1600], char* MobileNo)
  90. {
  91. char Temp[55];
  92. char Year[5];
  93. char filename[255];
  94. char *mon;
  95. char *day;
  96. char *yr;
  97. time_t tvec;
  98. struct tm* dtime;
  99.  
  100. time(&tvec);
  101. dtime = localtime(&tvec);
  102.  
  103. *mon = dtime->tm_mon + 1 ;
  104. *day = dtime->tm_mday ;
  105. *yr = dtime->tm_year ;
  106.  
  107. sprintf(filename,"DATA-%02d-02d-04d.txt",
  108. mon,
  109. day,
  110. yr);
  111.  
  112. // Filename Format YYYY-MM-DD
  113.  
  114. printf ("%s\n",filename);
  115.  
  116. FILE *fp;
  117.  
  118. fp=fopen(filename, "a+");
  119.  
  120. if ( (fputs(line2, fp)) == EOF)
  121. {
  122. printf("error write...");
  123. }
  124. if ( (fputs("\n", fp)) == EOF)
  125. {
  126. printf("error write1...");
  127. }
  128.  
  129. fclose(fp);
  130.  
  131.  
  132. }

This is the output when I try to run the program..
  1. 019xxxxxxx|019xxxxxxx|54344770|Customer Service|7TH FLOOR, MENARA CELCOM|JALAN RAJA MUDA ABDUL AZIZ|Kuala Lumpur|W PERSEKUTUAN KUALA LUMPUR||||50300||KHAIRUL BARIAH BINTI NORDIN|||||
  2. Segmentation fault

i've changed sumthing to the coding. i just changed sprintf(filename,"DATA-%02d-02d-04s.txt", ..) and I've got this when running it..
  1. 0192744210|099122844|d217585300104|LOT 6, ,|KUBANG KAWAH,|BACHOK|16300 PERUPOK|||||16300|MAL|AB WAHAB B MOHD ARIFF|AB WAHAB B MOHD ARIFF|571214-04-5423|5256704||
  2. DATA--1218443020-02d-04s.txt
  3. Segmentation fault

it seems like, there is sumthing wrong with filename..and no file actually was created..

Many thanks
Last edited by whitemoss; Nov 20th, 2006 at 10:45 pm.
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,679
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1504
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: error: too many arguments to function `mysql_query'

 
0
  #9
Nov 20th, 2006
the result set has 18 columns on each row, you sprintf() statement is attempting to use 19 columns (row[0] thru row[18] is 19 columns).

  1. char *mon;
  2. char *day;
  3. char *yr;
  4. time_t tvec;
  5. struct tm* dtime;
  6.  
  7. time(&tvec);
  8. dtime = localtime(&tvec);
  9.  
  10. *mon = dtime->tm_mon + 1 ;
  11. *day = dtime->tm_mday ;
  12. *yr = dtime->tm_year ;
That is wrong. mon is an ininitialized pointer that points to some random location in memory. Here is how to code that section
  1. int mon;
  2. int day;
  3. int yr;
  4. time_t tvec;
  5. struct tm* dtime;
  6.  
  7. time(&tvec);
  8. dtime = localtime(&tvec);
  9.  
  10. mon = dtime->tm_mon + 1 ;
  11. day = dtime->tm_mday ;
  12. yr = dtime->tm_year +1900;
Last edited by Ancient Dragon; Nov 20th, 2006 at 11:35 pm.
I told Santa what I wanted for Christmas and he washed my mouth out with soap.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 32
Reputation: whitemoss is an unknown quantity at this point 
Solved Threads: 0
whitemoss whitemoss is offline Offline
Light Poster

Re: error: too many arguments to function `mysql_query'

 
0
  #10
Nov 20th, 2006
Hi..thanks for the code..it's work..but then..the filename created is sumthing like this:

DATA-11-02d-02d-04s.txt

actually i already add for the hour section...supposedly the filename should be sumthing like this: DATA-HH-DD-MM-YYYY.txt...is there any missing tingy for the code?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:




Views: 3475 | Replies: 11
Thread Tools Search this Thread



Tag cloud for C
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC