Advertisement:
2by2host

Author Topic: SMF1 Trying to get Auto_increment value.  (Read 4685 times)

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,151
  • Gender: Male
Re: SMF1 Trying to get Auto_increment value.
« Reply #20 on: May 20, 2012, 03:12:05 PM »
So if the value isn't important, why bother going to the trouble of getting the auto-inc value in the first place?
Nice shot lol.

You need to provide more details as we might find an alternate solution then.
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.

Offline MrPhil

  • SMF Friend
  • SMF Hero
  • *
  • Posts: 6,652
Re: SMF1 Trying to get Auto_increment value.
« Reply #21 on: May 20, 2012, 05:35:51 PM »
The ID (autoincrement value) is usually the primary key, so accidentally having duplicates is really going to screw up your system!

<rant>Regarding $db_prefix, et al. issues, OK, I'll go away. I can't believe that they took terms and names such as $db_prefix with very specific standard meanings in SMF, and made them mean something entirely different for SSI. That's stupid.</rant>
Please do not PM me with support questions, unless I ask you to. Unsolicited PMs for support will be ignored. It's best to have questions and answers in public, so others can research a problem and learn about it without having to ask the question yet again. Thank you!
FAQs | SMF 1.1 fixes | Project ideas
-= From the ashes shall rise a sooty tern =-

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,013
    • wedgebook on Facebook
Re: SMF1 Trying to get Auto_increment value.
« Reply #22 on: May 20, 2012, 05:46:24 PM »
Actually, they do mean the same thing. It is the unified prefix that goes in front of the tables. Inside SMF it is merely the prefix on its own, outside SMF it has to include the DB table as well - but ultimately it means that wherever you are, {db_prefix}table_name will always be correct, and that holds true for both SMF 1 and 2.

While I get your frustration on this, from a design point of view, it's actually a blessing to work with, because that means you can use almost any routine inside SMF's code, from SSI, and have it all 'just work', regardless of where you are.

Offline MrMorph

  • Jr. Member
  • **
  • Posts: 112
Re: SMF1 Trying to get Auto_increment value.
« Reply #23 on: May 21, 2012, 08:15:52 AM »
So if the value isn't important, why bother going to the trouble of getting the auto-inc value in the first place?
Nice shot lol.

You need to provide more details as we might find an alternate solution then.

Nice shot ?  And from a 'support specialist' too !  I hope you guys are not going to get all superior and snide on me.

I'm curious; why do you all seem to think you can come up with an alternative solution when all you are doing is second guessing the nature of my project ?  What is the basis for your suggestions ?  It's nice that you care enough to make them though.

But all that was required was an answer to my original question.  Arantor did that with thanks.  I can assure you there is no need to worry about me screwing up my system.  I already said that the Auto_increment value is not critical in the sense you are all suggesting.  I understand what you are saying, but it has no bearing on this part of my code.  I really do not know what else I can say to stop you all worrying !

Anyway, I am done here. Goodbye, peace and thanks for all the fish  :)
« Last Edit: May 21, 2012, 08:57:51 AM by MrMorph »

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,013
    • wedgebook on Facebook
Re: SMF1 Trying to get Auto_increment value.
« Reply #24 on: May 21, 2012, 09:06:25 AM »
The reason I push for alternatives is because in my experience (both personally and professionally), someone asking for a detail like this, even when presented with multiple caveats is likely looking down a tunnel for a solution, rather than doing it properly.

This is the part we don't understand - why bother with all the hassle of getting an auto-increment when you don't need it for referential integrity? I'm also bothered that it might make life difficult for you in the future for maintenance, because again this is something I normally end up getting contracted to fix.

But hey, if you're sure that it's the right answer for you, good luck with it. I just hope it's not going into the mod you're looking to write for SMF 1 and 2 and then sell, because I really don't have to want to pick up any pieces when people run into support issues...

Offline MrMorph

  • Jr. Member
  • **
  • Posts: 112
Re: SMF1 Trying to get Auto_increment value.
« Reply #25 on: May 21, 2012, 09:31:04 AM »
Thanks for your explanation and it does do you credit that you look for problems like this.

I'll fill you in a bit about me.  I have been programming since I was 11; writing machine code on my ZX Spectrum; did O and A level computer science and studied Computer Science at University too learning wonderful languages like C and Modular 2 (most of which I have long forgotten about) and more recently I gained some Web developer & IT qualifications.  Now I am in my 40s and still enjoying it every day.

That's the short version.  But it's just to set your mind at ease a little really.  I have spent years writing, editing and designing code. To be fair I have only been working with PHP for maybe 5 years now, I still have stuff to learn.  I still have a lot to learn about the SMF system too and it's internals, but I really like the way both versions have been written.

Often rather than sift through the code and figure out what they did I simply ask if anyone knows how one bit works or why it doesn't work as expected.  Sometimes that's all I need to know.

I tend not to have tunnel vision when I code, but I know what you mean.  Currently I am spending hours on the security aspects of my mod and I will try not to leave a stone unturned.  I am never satisfied with the code I write unless it's something simple.

But I never considered myself an expert.  But I do try to do a proper job, there are no short-cuts here.  That's why I said I would take people's suggestions seriously and I did; it's just that some of them I was able to dismiss.  It won't stop me going back to look at it again though, now that you guys have pointed out some things to look at.

If you weren't there to pick up the pieces then you wouldn't have a job maybe lol ;)  But I get your point.

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,151
  • Gender: Male
Re: SMF1 Trying to get Auto_increment value.
« Reply #26 on: May 21, 2012, 09:45:34 AM »
So if the value isn't important, why bother going to the trouble of getting the auto-inc value in the first place?
Nice shot lol.

You need to provide more details as we might find an alternate solution then.

Nice shot ?  And from a 'support specialist' too !  I hope you guys are not going to get all superior and snide on me.
Nah not at all. I'm a noobie when it comes to MySQL, everybody knows that :P

Quote
I'm curious; why do you all seem to think you can come up with an alternative solution when all you are doing is second guessing the nature of my project ?  What is the basis for your suggestions ?  It's nice that you care enough to make them though.
Because you won't get the trouble you have now with the alternate suggestion, at least that's what I hope/think.

Quote
But all that was required was an answer to my original question.  Arantor did that with thanks.  I can assure you there is no need to worry about me screwing up my system.  I already said that the Auto_increment value is not critical in the sense you are all suggesting.  I understand what you are saying, but it has no bearing on this part of my code.  I really do not know what else I can say to stop you all worrying !
Then our answer is, if it's not important then why bother gathering it? It must have some meaning if you are gathering it right?
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.

Offline MrMorph

  • Jr. Member
  • **
  • Posts: 112
Re: SMF1 Trying to get Auto_increment value.
« Reply #27 on: May 21, 2012, 09:57:26 AM »
Quote
Nah not at all. I'm a noobie when it comes to MySQL, everybody knows that

Fair play, some times it's just not so easy to figure out how a comment is meant to be taken in plain text :)

Quote
Because you won't get the trouble you have now with the alternate suggestion, at least that's what I hope/think.

OK, but I am not having trouble with my solution.  The trouble was I could not understand why $db_prefix was returning the result it did.   We are testing this thing btw...  ;)

Quote
Then our answer is, if it's not important then why bother gathering it? It must have some meaning if you are gathering it right?

Hmmm, don't know how to answer this again... Yes it has meaning...maybe read over what you quoted again, that's the best answer I have come up with so far.

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,151
  • Gender: Male
Re: SMF1 Trying to get Auto_increment value.
« Reply #28 on: May 21, 2012, 10:35:01 AM »
Quote
Nah not at all. I'm a noobie when it comes to MySQL, everybody knows that

Fair play, some times it's just not so easy to figure out how a comment is meant to be taken in plain text :)
Yeah, plain text is plain stupid. :P

Quote
Quote
Because you won't get the trouble you have now with the alternate suggestion, at least that's what I hope/think.

OK, but I am not having trouble with my solution.  The trouble was I could not understand why $db_prefix was returning the result it did.
I think it's doing this so you can use something like this:
Code: [Select]
`database name`.`table_name`As Arantor (or osmeone else) already said, the SMF database is not loaded. Though I don't understand why it puts it in the prefix either.

Quote
We are testing this thing btw...  ;)
I hoped so lmao

Quote
Quote
Then our answer is, if it's not important then why bother gathering it? It must have some meaning if you are gathering it right?

Hmmm, don't know how to answer this again... Yes it has meaning...maybe read over what you quoted again, that's the best answer I have come up with so far.
Mmkay, but if we knew what ya want maybe we could provide a better or alternative solution so you don't have to fiddle with this.

Anyway I found this for ya:
http://stackoverflow.com/questions/933565/get-auto-increment-value-with-mysql-query

Maybe you can do something with that as it returns weird stuff for you.
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.

Offline MrMorph

  • Jr. Member
  • **
  • Posts: 112
Re: SMF1 Trying to get Auto_increment value.
« Reply #29 on: May 21, 2012, 11:05:00 AM »
Quote
I think it's doing this so you can use something like this:
Code: [Select]
`database name`.`table_name`As Arantor (or osmeone else) already said, the SMF database is not loaded. Though I don't understand why it puts it in the prefix either.

Yep I think you and Arantor have that right.

With regard to SSI and the way it works there :

This does work for things like SELECT, whereby it attaches the database name and prefix (if any) to the query.  All well and good and all my SELECTS work as expected.

But where you need to perform a LIKE (ie a pattern match), then it won't work because it's not simply the prefix by itself, but also the database name.

In my case $db_prefix contains
Code: [Select]
`smf1`.
So when I do something like this :

Code: [Select]
$result = db_query("
SHOW TABLE STATUS
FROM $db_name
LIKE '{$db_prefix}merc_message_log'"
, false, false);

By the time it is interpreted the query string literally becomes this :

Code: [Select]
SHOW TABLE STATUS FROM smf1 LIKE '`smf1`.merc_message_log'
Which is not gonna work and indeed it doesn't.  At least this is what it seems like to me atm.

Thanks for that link, it's useful but I would still encounter the same problem.

Quote
Quote
We are testing this thing btw...  ;)
I hoped so lmao

 :D Yeah this won't be finished for weeks, I am too much of a perfectionist !

Offline MrMorph

  • Jr. Member
  • **
  • Posts: 112
Re: SMF1 Trying to get Auto_increment value.
« Reply #30 on: May 21, 2012, 11:10:33 AM »
I think I will just have to run a query on the plain prefix...would work.  Unless it is also stored in some other place already loaded...I'll dig around a bit more.

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,151
  • Gender: Male
Re: SMF1 Trying to get Auto_increment value.
« Reply #31 on: May 21, 2012, 11:12:50 AM »
Does it work if you remove the ' quotes? Or does it fail to work how you want it, there, too?

EDIT: Reading your new post, try print_ring $context and $db_prefix, like so:
Code: [Select]
print_r($context, $db_prefix);
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.

Offline MrMorph

  • Jr. Member
  • **
  • Posts: 112
Re: SMF1 Trying to get Auto_increment value.
« Reply #32 on: May 21, 2012, 11:22:50 AM »
Does it work if you remove the ' quotes? Or does it fail to work how you want it, there, too?

EDIT: Reading your new post, try print_ring $context and $db_prefix, like so:
Code: [Select]
print_r($context, $db_prefix);

Nope removing the quotes just results in a mysql_error.  The quotes need to be there to form a proper query.

$db_prefix is `smf1`.

$context does not hold the setting, nor does $settings.

I think whoever wrote that part just did not expect it to be used the way I am using it, ie in a pattern matching exercise.

I can work around it, just would have been simpler...  I think the way it is done works in the majority of cases that the coder anticipated and that's fair enough really.

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,151
  • Gender: Male
Re: SMF1 Trying to get Auto_increment value.
« Reply #33 on: May 21, 2012, 11:30:11 AM »
Does it work if you remove the ' quotes? Or does it fail to work how you want it, there, too?

EDIT: Reading your new post, try print_ring $context and $db_prefix, like so:
Code: [Select]
print_r($context, $db_prefix);

Nope removing the quotes just results in a mysql_error.  The quotes need to be there to form a proper query.

$db_prefix is `smf1`.

$context does not hold the setting, nor does $settings.

I think whoever wrote that part just did not expect it to be used the way I am using it, ie in a pattern matching exercise.
Okay, I'm lost at this now. Can't fire a feature request/bug report either as 1.x is frozen except for security issues, which this clearly is not.

Quote
I can work around it, just would have been simpler...  I think the way it is done works in the majority of cases that the coder anticipated and that's fair enough really.
I suggest you work around it by creating a new variable then, and storing the prefix in there.
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.

Offline Arantor

  • SMF Legend
  • *
  • Posts: 51,013
    • wedgebook on Facebook
Re: SMF1 Trying to get Auto_increment value.
« Reply #34 on: May 21, 2012, 01:21:49 PM »
Thing is, it's exactly the same in 2.0 and for exactly the same reason.

But you see, if I understood why you wanted the auto-increment, I could probably suggest a better way to get it...

Offline Yoshi

  • Customizer
  • SMF Hero
  • *
  • Posts: 8,151
  • Gender: Male
Re: SMF1 Trying to get Auto_increment value.
« Reply #35 on: May 21, 2012, 01:40:17 PM »
But you see, if I understood why you wanted the auto-increment, I could probably suggest a better way to get it...
That's what I've been trying to tell, too.
My Mods / [WIP] Mod Builder / GitHub profile / "A programmer is just a tool which converts caffeine into code."
Quote
<FLAMER> Marketing is about to get into drug activities maybe... but we will see about that later on :P
<Yoshi2889> We're getting free drugs?
<CoreISP> He's talking about caffeine man, damn pen lifter.