473,385 Members | 1,325 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Proc*C Help Required for Line ny Line Help as am new to Pro*C

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h>
  2. #include <sqlca.h>
  3. #include <sqlcpr.h>
  4.  
  5. struct my_vc_ptr
  6. {
  7. unsigned short len;
  8. unsigned char arr[32767];
  9. };
  10.  
  11. typedef struct my_vc_ptr my_vc_ptr;
  12. my_vc_ptr *vc_ptr;
  13. EXEC SQL BEGIN DECLARE SECTION;
  14. VARCHAR *names;
  15. int limit; 
  16. char *username = "scott/tiger";
  17. EXEC SQL END DECLARE SECTION;
  18. void sql_error();
  19. extern void sqlvcp(), sqlgls();
  20. main()
  21. {
  22. unsigned int vcplen, function_code, padlen, buflen;
  23. int i;
  24. char stmt_buf[120];
  25. EXEC SQL WHENEVER SQLERROR DO sql_error();
  26. EXEC SQL CONNECT :username;
  27. printf("\nConnected.\n");
  28.  
  29. EXEC SQL SELECT COUNT(*) INTO :limit FROM emp;
  30. EXEC SQL DECLARE emp_name_cursor CURSOR FOR
  31. SELECT ename FROM emp;
  32. EXEC SQL FOR :limit OPEN emp_name_cursor;
  33. vcplen = 10;
  34. sqlvcp(&vcplen, &padlen);
  35. printf("Actual array length of VARCHAR is %ld\n", padlen);
  36. names = (VARCHAR *) malloc((sizeof (short) +
  37. (int) padlen) * limit);
  38. if (names == 0)
  39. {
  40. printf("Memory allocation error.\n");
  41. exit(1);
  42. }
  43. for (vc_ptr = (my_vc_ptr *) names, i = 0; i < limit; i++)
  44. {
  45. vc_ptr->len = (short) padlen;
  46. vc_ptr = (my_vc_ptr *)((char *) vc_ptr +
  47. padlen + sizeof (short));
  48. }
  49. EXEC SQL FOR :limit FETCH emp_name_cursor INTO :names;
  50. printf("Employee names--\n");
  51. for (vc_ptr = (my_vc_ptr *) names, i = 0; i < limit; i++)
  52. {
  53. printf
  54. ("%.*s\t(%d)\n", vc_ptr->len, vc_ptr->arr, vc_ptr->len);
  55. vc_ptr = (my_vc_ptr *)((char *) vc_ptr +
  56. padlen + sizeof (short));
  57. }
  58.  
  59. buflen = (long) sizeof (stmt_buf);
  60. sqlgls(stmt_buf, &buflen, &function_code);
  61. if (buflen != 0)
  62. {
  63. printf("The SQL statement was--\n%.*s\n", buflen, stmt_buf);
  64. printf("The statement length is %ld\n", buflen);
  65. printf("The function code is %ld\n", function_code);
  66. EXEC SQL COMMIT RELEASE;
  67. exit(0);
  68. }
  69. else
  70. {
  71. printf("The SQLGLS function returned an error.\n");
  72. EXEC SQL ROLLBACK RELEASE;
  73. exit(1);
  74. }
  75. }
  76. void sql_error()
  77. {
  78. char err_msg[512];
  79. int buf_len, msg_len;
  80. EXEC SQL WHENEVER SQLERROR CONTINUE;
  81. buf_len = sizeof (err_msg);
  82. sqlglm(err_msg, &buf_len, &msg_len);
  83. printf("%.*s\n", msg_len, err_msg);
  84. EXEC SQL ROLLBACK RELEASE;
  85. exit(1);
  86. }
  87.  
Mar 3 '07 #1
2 2149
Mainly require help on the following Lines out of the full Code , what does these lines infer


names = (VARCHAR *) malloc((sizeof (short) +
(int) padlen) * limit);

vc_ptr->len = (short) padlen;
vc_ptr = (my_vc_ptr *)((char *) vc_ptr +
padlen + sizeof (short));

buflen = (long) sizeof (stmt_buf);
Mar 3 '07 #2
Also Help required for some Documentation on C usages and Syntaxes.
Mar 3 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Derrick D. Daugherty | last post by:
ehlo all I'm trying to compile an app over from sol26 to a recent debian x86 system and I'm not having much luck with getting the precompiler to build some logic we require. I've seen posts...
4
by: Michael Trosen | last post by:
Hi Everyone, I hope someone can help, I'm pretty new to pro*c programming. I have the following application setup: a pro*c program calls a stored procedure and recieves a cursor back: the...
9
by: Wolfgang Kreuzer | last post by:
Try hard to become familiar with T-SQL. Can anybodey tell me the best way to deal with set's provided by a stored procedure. Til yesterday I thougt trapping set in temp table using INSERT EXEC...
4
by: Nyul | last post by:
Gurus, I have a verb big problem which I'm unable to explain. We have a DB2 V6.1.0 on AIX 4.3 I want to make a C stored procedure which at the end will be called by a PHP script. The...
4
by: CSDunn | last post by:
Hello, I have a combo box (Combo7) that needs to call a function during the After Update event of the combo box. The function resides in an Access 2000 ADP Module called MMAnswerData_code. The...
3
by: wackyphill | last post by:
Using ADO.NET Or regular queries on SQL Server, is there a good way of determining if a Stored Proc will be returning a result set or if it is a non-query that does all I/O through parameters? ...
14
by: Roy | last post by:
Apologies for the cross-post, but this truly is a two-sided question. Given the option of creating Looping statements within a stored proc of sql server or in the code-behind of an .net webpage,...
7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
2
by: appunni | last post by:
Hi, I am trying to execute an DB2 SQL stored proc in mainframe. my proc is CREATE PROCEDURE db2t.abuproc () LANGUAGE SQL external name abuproc
3
by: erict | last post by:
Access 2002-2003 runtime App works fine on single proc machines but we are rolling out a tech refresh and we found this case where the code appears to simply slip through the open form command and...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.