5 Replies - 196 Views - Last Post: 19 July 2012 - 07:29 AM Rate Topic: -----

#1 abhishekgaur  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-July 12

searchCriteria->Timestamp one timestamp) in other have to create r

Posted 18 July 2012 - 11:57 PM

char * createQuery (Image_Desc *searchCriteria, SEARCHTYPE stype,char *other)
{
	char *ret = NULL;
	int init = 0;
	char *Query = NULL;
	char subQuery[BUFFSIZE]={0};

	if ((stype > 0) && (stype < 10) && searchCriteria) {
		Query = (char *) MALLOC(BUFFSIZE);
		switch(stype){

		case SE_METADATA:
		case SE_RANGETIME:
			{
				sprintf(Query, "select * from DATA");

				if (searchCriteria->ImageID) {
					sprintf(subQuery, "%s %d", " where Img_ID is ", searchCriteria->ImageID);
					strcat(Query, subQuery);
					init = 1;
				}

				if (searchCriteria->ImageType) {
					memset(subQuery, 0, BUFFSIZE);
					if (1 == init) {
						sprintf(subQuery, "%s '%c'", " And Img_Type is ", searchCriteria->ImageType);
					} else {
						sprintf(subQuery, "%s '%c'", " where Img_Type is ", searchCriteria->ImageType);
						init = 1;
					}

					strcat(Query, subQuery);
				}

				if (searchCriteria->ImageFilePath) {
					memset(subQuery, 0, BUFFSIZE);
					if (1 == init) {
						sprintf(subQuery, "%s '%s'", " And Img_FilePath is ", searchCriteria->ImageFilePath);
					} else {
						sprintf(subQuery, "%s '%s'", " where Img_FilePath is ", searchCriteria->ImageFilePath);
						init = 1;
					}
					strcat(Query, subQuery);
				}

				if (searchCriteria->Timestamp) {
					memset(subQuery, 0, BUFFSIZE);
					if (1 == init) {
						sprintf(subQuery, "%s '%s'", " And Img_Timestamp is ", searchCriteria->Timestamp);
					} else {
						sprintf(subQuery, "%s '%s'", " where Img_Timestamp is ", searchCriteria->Timestamp);
						init = 1;
					}
					strcat(Query, subQuery);

					if (other) {
						
						
						
						strcat(Query, "WHERE DATA.Timestamp > '2012/6/05' AND DATA.TIMESTAMP <= '2012/7/06';");
					}
				}


MOD EDIT: Added code tags. When posting code...USE CODE TAGS!!!

:code:

This post has been edited by JackOfAllTrades: 19 July 2012 - 03:52 AM


Is This A Good Question/Topic? 0
  • +

Replies To: searchCriteria->Timestamp one timestamp) in other have to create r

#2 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: searchCriteria->Timestamp one timestamp) in other have to create r

Posted 19 July 2012 - 12:00 AM

Put your code in [code] tags.

I see beautiful code that is ripe for SQL injection attacks...
Posted Image

Anyway, what is the specific problem you need help with in your code above?

This post has been edited by Skydiver: 19 July 2012 - 12:02 AM

Was This Post Helpful? 1
  • +
  • -

#3 abhishekgaur  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-July 12

Re: searchCriteria->Timestamp one timestamp) in other have to create r

Posted 19 July 2012 - 12:32 AM

actually one time stamp is coming from searchCriteria->Timestamp and in other i want to add the other time stamp so that a specific range is formed but i am not able to do that :( i want to inject query so that a range of date can be formed .
Was This Post Helpful? 0
  • +
  • -

#4 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: searchCriteria->Timestamp one timestamp) in other have to create r

Posted 19 July 2012 - 12:40 AM

Why are you "not able to do that"? What have you tried previously? Can you show us your past attempts?
Was This Post Helpful? 0
  • +
  • -

#5 abhishekgaur  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 18-July 12

Re: searchCriteria->Timestamp one timestamp) in other have to create r

Posted 19 July 2012 - 01:47 AM

if (other) {



strcat(Query, "WHERE DATA.Timestamp > '2012/6/05' AND DATA.TIMESTAMP <= '2012/7/06';");
}
} tried this
Was This Post Helpful? 0
  • +
  • -

#6 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3467
  • View blog
  • Posts: 10,687
  • Joined: 05-May 12

Re: searchCriteria->Timestamp one timestamp) in other have to create r

Posted 19 July 2012 - 07:29 AM

But in the lines above that you were building string using sprintf(), what makes this any different?
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1