我在MySQL中有十进制(10,2)列商店产品价格。
Eloquent获取它,我们有:while(s[a] && s[a] != d)
然后我设置printf("*%s+", *a);
,char** split_at (char* s, char d)
{
int numdelim = 0;
char* t = s; // need a copy
while(*t)
{
numdelim += *t == d;
++t;
}
char** final = (char**)malloc((numdelim + 2) * sizeof(char*));
char** f = final; // pointer to current position within final
t = s; // re-assign t, using s as start pointer for new strings
while(*t) // see above
{
if(*t == d) // delimiter found!
{
// can subtract pointers --
// as long as they point to the same array!!!
char* n = (char*)malloc(t - s + 1); // +1: terminating null
*f++ = n; // store in position pointer and increment it
while(s != t) // copy the string from start to current t
*n++ = *s++;
*n = 0; // terminate the new string
}
++t; // next character...
}
*f = NULL; // and finally terminate the string array
return final;
}
返回$product->getOriginal('price') // string(6) "985.00"
字段为脏
然后如果我$product->price = (float)985
雄辩地进行更新查询,但值相同,不需要更新。
我不希望每次都设置$product->getDirty('price')
查询来设置相同的值,我只想在价格真正发生变化时进行price
次查询
我制作此代码
$product->save()
和UPDATE
它适合我,但我认为这不是好的做法