问:
applicationSettings in external file
I have been trying to use some code found a bit down on http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource%28VS.85%29.aspx to place my application settings in an external file but cant get it to work.

App.config:

```<code><?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings">
          <section name="ConsoleApplication1.Settings" />
        </sectionGroup>
    </configSections>
    <applicationSettings>
        <ConsoleApplication1.Settings configSource="externalSettings.config" />
    </applicationSettings>
</configuration>
</code>```

externalSettings.config:

```<code><ConsoleApplication1.Settings>
  <setting name="TestSetting" serializeAs="String">
    <value>Hello</value>
  </setting>
</ConsoleApplication1.Settings>
</code>```

I am trying to use the settings like you normally would:

```<code>var test = ConsoleApplication1.Settings.Default.TestSetting;
</code>```

答:
I did come across the same issue.
It was resolved using correct namespace in the config

Settings class:

```<code>namespace ConsoleApp1.Properties {

[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

    private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

    public static Settings Default {
        get {
            return defaultInstance;
        }
    }

    [global::System.Configuration.ApplicationScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public string TestSetting {
        get {
            return ((string)(this["TestSetting"]));
        }
    }
}
}
</code>```

usage:

```<code>var test = ConsoleApp1.Properties.Settings.Default.TestSetting;
</code>```

config:

```<code><?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  <section name="ConsoleApp1.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
  <applicationSettings>
    <Settings configSource="externalSettings.config" />
  </applicationSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
</configuration>
</code>```

externalSettings.config:

```<code><ConsoleApp1.Settings>
<setting name="TestSetting" serializeAs="String">
 <value>Hello</value>
</setting>
</ConsoleApp1.Settings>
</code>```

Title: applicationSettings in external file

Body:
I have been trying to use some code found a bit down on http://msdn.microsoft.com/en-us/library/system.configuration.sectioninformation.configsource%28VS.85%29.aspx to place my application settings in an external file but cant get it to work.

App.config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
    <configSections>
        <sectionGroup name="applicationSettings">

        </sectionGroup>
    </configSections>
    <applicationSettings>
        <ConsoleApplication1.Settings configSource="externalSettings.config" />
    </applicationSettings>
</configuration>

externalSettings.config:

<ConsoleApplication1.Settings>
  <setting name="TestSetting" serializeAs="String">
    <value>Hello</value>
  </setting>
</ConsoleApplication1.Settings>

I am trying to use the settings like you normally would:

var test = ConsoleApplication1.Settings.Default.TestSetting;

Body:
I did come across the same issue.
It was resolved using correct namespace in the config

Settings class:

namespace ConsoleApp1.Properties {

[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.0.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {

    private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));

    public static Settings Default {
        get {
            return defaultInstance;
        }
    }

    [global::System.Configuration.ApplicationScopedSettingAttribute()]
    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
    public string TestSetting {
        get {
            return ((string)(this["TestSetting"]));
        }
    }
}
}

usage:

var test = ConsoleApp1.Properties.Settings.Default.TestSetting;

config:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="applicationSettings" type="System.Configuration.ApplicationSettingsGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
  <section name="ConsoleApp1.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</sectionGroup>
</configSections>
  <applicationSettings>
    <Settings configSource="externalSettings.config" />
  </applicationSettings>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
  </startup>
</configuration>

externalSettings.config:

<ConsoleApp1.Settings>
<setting name="TestSetting" serializeAs="String">
 <value>Hello</value>
</setting>
</ConsoleApp1.Settings>


来源: stackexchange

问:
change the state of the child component
I am having a Parent Component and a child component

```<code>export default class CityPart extends Component {
    constructor(props)
    {
        super(props);
        this.state ={
            citylist: citylist
            selectedflag:1
        }

    }
    Clickme(idd){
     this.setstate({selectedflag:idd})
}
    render() {
        return (
        <div className="CityPartMain">
            {this.state.citylist.map((item)=>{
                return (
                <EachCity name ={item.name} key={item.id}
                id={item.id}
                selected={this.state.selected}
                Clickme ={this.Clickme}
                />
                )
            })}
        </div>
        );

    }
}
</code>```

```<code>export default class EachCity extends Component {
    render() {
        const {name,id,selected,Clickme} = this.props;
        return (
            <button
            onClick={this.Clickme(id)}
            className={selected===parseInt(id,10)?"selectedcity": "EachCityMain"}>
            <p>{name}</p>
            </button>
        );
    }
}
</code>```

whenever i click on the button i want that id should come to my parent component and it should get updated in the selectedflag of the parent state.

Thanks for help in advance.

答:
You have made two mistakes.
First one is in your parent - this is how you should implement method Clickme:

```<code>Clickme = (id) => {
    this.setState({selectedflag:idd})
}
</code>```

In your implementation this means object, which is calling method (child), so this.setState() will work for child.
When you use lambda expression - it will work for parent.

Second mistake is how are you calling Clickme in your child component.
You should make it like:

```<code><button
    onClick={() => Clickme(id)}
    className={selected === parseInt(id,10) ? "selectedcity" : "EachCityMain"}
    >
        <p>{name}</p>
</button>
</code>```

If you are calling function without parameters, you can just pass function to onClick. In your case you have to create anonymous function to call it with parameter. Additionaly this is unnecessary.

ContentLicense: CC BY-SA 4.0

Title: change the state of the child component

Body:
I am having a Parent Component and a child component

export default class CityPart extends Component {
    constructor(props)
    {
        super(props);
        this.state ={
            citylist: citylist
            selectedflag:1
        }

    }
    Clickme(idd){
     this.setstate({selectedflag:idd})
}
    render() {
        return (

            {this.state.citylist.map((item)=>{
                return (
                <EachCity name ={item.name} key={item.id}
                id={item.id}
                selected={this.state.selected}
                Clickme ={this.Clickme}
                />
                )
            })}

        );

    }
}

export default class EachCity extends Component {
    render() {
        const {name,id,selected,Clickme} = this.props;
        return (
            <button
            onClick={this.Clickme(id)}
            className={selected===parseInt(id,10)?"selectedcity": "EachCityMain"}>

{name}

            </button>
        );
    }
}

whenever i click on the button i want that id should come to my parent component and it should get updated in the selectedflag of the parent state.

Thanks for help in advance.

Body:
You have made two mistakes.
First one is in your parent - this is how you should implement method Clickme:

Clickme = (id) => {
    this.setState({selectedflag:idd})
}

In your implementation this means object, which is calling method (child), so this.setState() will work for child.
When you use lambda expression - it will work for parent.

Second mistake is how are you calling Clickme in your child component.
You should make it like:

<button
    onClick={() => Clickme(id)}
    className={selected === parseInt(id,10) ? "selectedcity" : "EachCityMain"}
    >
        <p>{name}</p>
</button>

If you are calling function without parameters, you can just pass function to onClick. In your case you have to create anonymous function to call it with parameter. Additionaly this is unnecessary.


问:
asp.net and cookies special characters
Have found very interesting issue in asp.net with cookies:
when adding cookie with value like test&
using

```<code>HttpCookie cookie = new HttpCookie("test", "test&");
Response.Cookies.Add(cookie);
</code>```

and then trying to retrieve value Request.Cookies["test"] trailing ampersand is lost. If it is not trailing it is not lost. In firebug or javascript data is correct so it is asp.net specific I think.
Of course mostly could say just use UrlEncode. But is it really necessary? Is there any list of disallowed charters for cookies (because I think it is smaller than for URLs)?
I have found similar topic but there is no & symbol in restricted list:
Allowed characters in cookies

答:
The ampersand is not an allowed character in a cookie. It's necessary to encode the cookie data with the UrlEncode method.

```<code>System.Web.HttpUtility.UrlEncode(cookie);
</code>```

See also these SO questions/answers:

Broken string in cookie after ampersand (javascript)

How do you use an Ampersand in an HTTPCookie in VB.NET?

ContentLicense: CC BY-SA 3.0

Title: asp.net and cookies special characters

Body:
Have found very interesting issue in asp.net with cookies:
when adding cookie with value like test&
using

HttpCookie cookie = new HttpCookie("test", "test&");
Response.Cookies.Add(cookie);

and then trying to retrieve value Request.Cookies["test"] trailing ampersand is lost. If it is not trailing it is not lost. In firebug or javascript data is correct so it is asp.net specific I think.
Of course mostly could say just use UrlEncode. But is it really necessary? Is there any list of disallowed charters for cookies (because I think it is smaller than for URLs)?
I have found similar topic but there is no & symbol in restricted list:
Allowed characters in cookies

Body:
The ampersand is not an allowed character in a cookie. It's necessary to encode the cookie data with the UrlEncode method.

System.Web.HttpUtility.UrlEncode(cookie);

See also these SO questions/answers:

Broken string in cookie after ampersand (javascript)

How do you use an Ampersand in an HTTPCookie in VB.NET?


问:
Why/how is an additional variable needed in matching repeated arbitary character with capture groups?
I'm matching a sequence of a repeating arbitrary character, with a minimum length, using a perl6 regex.

After reading through https://docs.perl6.org/language/regexes#Capture_numbers and tweaking the example given, I've come up with this code using an 'external variable':

```<code>#uses an additional variable $c
perl6 -e '$_="bbaaaaawer"; /((.){} :my $c=$0; ($c)**2..*)/ && print $0';

#Output:  aaaaa
</code>```

To aid in illustrating my question only, a similar regex in perl5:

```<code>#No additional variable needed
perl -e ' $_="bbaaaaawer"; /((.)\2{2,})/ && print $1';
</code>```

Could someone enlighten me on the need/benefit of 'saving' $0 into $c and the requirement of the empty {}? Is there an alternative (better/golfed) perl6 regex that will match?

Thanks in advance.

答:
Option #1: Don't sub-capture a pattern that includes a back reference

$0 is a back reference1.

If you omit the sub-capture around the expression containing $0, then the code works:

```<code>$_="bbaaaaawer"; / (.) $0**2..* / && print $/; # aaaaa
</code>```

Then you can also omit the {}. (I'll return to why you sometimes need to insert a {} later in this answer.)

But perhaps you wrote a sub-capture around the expression containing the back reference because you thought you needed the sub-capture for some other later processing.

There are often other ways to do things. In your example, perhaps you wanted a way to be able to count the number of repeats. If so, you could instead write:

```<code>$_="bbaaaaawer";
/ (.) $0**2..* /;
print $/.chars div $0.chars; # 5
</code>```

Job done, without the complications of the following sections.

Option #2. Sub-capture without changing the current match object during matching of the pattern that includes a back reference

Maybe you really need to sub-capture a match of an expression that includes a back reference.

This can still be done without needing to surround the $0 with a sub-capture. This saves the problems discussed in the third section below.

You can use this technique if you don't need to have sub-sub-captures of the expression and the expression isn't too complicated:

```<code>$_="bbaaaaawer";
/ (.) $<capture-when-done>=$0**2..* /;
print $<capture-when-done>.join; # aaaa
</code>```

This sub-captures the result of matching the expression in a named capture but avoids inserting an additional sub-capture context around the expression (which is what causes the complications discussed in the next section).

Unfortunately, while this technique will work for the expression in your question ($0**2..*) it won't if an expression is complex enough to need grouping. This is because the syntax $<foo>=[...] doesn't work. Perhaps this is fixable without hurting performance or causing other problems.2

Option #3. Use a saved back reference inside a sub-capture

Finally we arrive at the technique you've used in your question.

Automatically available back references to sub-captures (like $0) cannot refer to sub-captures that happened outside the sub-capture they're written in. Update See "I'm (at least half) wrong!" note below.

So if, for any reason, you have to create a sub-capture (using either (...) or <...>) then you must manually store a back reference in a variable and use that instead.

Before we get to a final section explaining in detail why you must use a variable, let's first complete an initial answer to your question by covering the final wrinkle.

{} forces "publication" of match results thus far

The {} is necessary to force the :my $c=$0; to update each time it's reached using the current regex/grammar engine. If you don't write it, then the regex engine fails to update $c to a capture of 'a' and instead leaves it stuck on a capture of 'b'.

Please read "Publication" of match variables by Rakudo.

Why can't a sub-capture include a back reference to captures that happened outside that sub-capture?

First, you have to take into account that matching in P6 is optimized for the nested matching case syntactically, semantically, and implementation wise.

In particular, if, when writing a regex or grammar, you write a numbered capture (with (...)), or a named rule/capture (with <foo>), then you've inserted a new level in a tree of sub-patterns that are dynamically matched/captured at run-time.

See jnthn's answer for why and Brad's for some discussion of details.

What I'll add to those answers is a (rough!) analogy, and another discussion of why you have to use a variable and {}.

The analogy begins with a tree of sub-directories in a file system:

```<code>/
  a
  b
    c
    d
</code>```

The analogy is such that:

The directory structure above corresponds to the result of a completed match operation.

After an overall match or grammar parse is complete, the match object $/ refers (analogously speaking) to the root directory.3

The sub-directories correspond to sub-captures of the match.

Numbered sub-matches/sub-captures $0 and $1 at the top level of the match operation shown below these bullet points corresponds to sub-directories a and b. The numbered sub-captures of the top level $1 sub-match/sub-capture corresponds to the c and d sub-directories.

During matching $/ refers to the "current match object" which corresponds to the "current working directory".

It's easy to refer to a sub-capture (sub-directory) of the current  match (current working directory).

It's impossible to refer to a sub-capture (sub-directory) outside the current match (current working directory) unless you've saved a reference to that outside directory (capture) or a parent of it. That is, P6 does not include an analog of .. or /! Update I'm happy to report that I'm (at least half) wrong! See What's the difference between $/ and $¢ in regex?.

If file system navigation didn't support these back references towards the root then one thing to do would be to create an environment variable that stored a particular path. That's roughly what saving a capture in a variable in a P6 regex is doing.

The central issue is that a lot of the machinery related to regexes is relative to "the current match". And this includes $/, which refers to the current match and back references like $0, which are relative to the current match. Update See "I'm (at least half) wrong!" note above.

Thus, in the following, which is runnable via tio.run here, it's easy to display 'bc' or 'c' with a code block inserted in the third pair of parens...

```<code>$_="abcd";
m/ ( ( . ) ( . ( . ) { say $/ } ( . ) ) ) /; # ｢bc｣␤ 0 => ｢c｣␤
say $/;                                      # ｢abcd｣␤ etc.
</code>```

...but it's impossible to refer to the captured ｢a｣ in that third pair of parens without storing ｢a｣'s capture in a regular variable.  Update See "I'm (at least half) wrong!" note above.

Here's one way of looking at the above match:

```<code>  ↓ Start TOP level $/
m/ ( ( . ) ( . ( . ) { say $/ } ( . ) ) ) /; # captures ｢abcd｣

    ↓ Start first sub-capture; TOP's $/[0]
   (                                    )    # captures ｢abcd｣

      ↓ Start first sub-sub-capture; TOP's $/[0][0]
     ( . )                                   # captures ｢a｣

            ↓ Start *second* sub-sub-capture; TOP's $/[0][1]
           (                          )      # captures ｢bcd｣

                ↓ Start sub-sub-sub-capture; TOP's $/[0][1][0]
               ( . )                         # captures ｢c｣

                     { say $/ }              # ｢bc｣␤ 0 => ｢c｣␤

                                 ( . )       # captures 'd'
</code>```

If we focus for a moment on what $/ refers to outside of the regex (and also directly inside the /.../ regex, but not inside sub-captures), then that $/ refers to the overall Match object, which ends up capturing ｢abcd｣. (In the filesystem analogy this particular $/ is the root directory.)

The $/ inside the code block inside the second sub-sub-capture refers to a lower level match object, specifically the one that, at the point the say $/ is executed, has already matched ｢bc｣ and will go on to have captured ｢bcd｣ by the end of the overall match.

But there's no built in way to refer to the sub-capture of 'a', or the overall capture (which at that point would be 'abc'), from within the sub-capture surrounding the code block. Update See "I'm (at least half) wrong!" note above.

Hence you have to do something like what you've done.

A possible improvement?

What if there were a direct analog in P6 regexes for specifying the root? Update See "I'm (at least half) wrong!" note above.

Here's an initial cut at this that might make sense. Let's define a grammar:

```<code>my $*TOP;
grammar g {
  token TOP { { $*TOP := $/ } (.) {} <foo> }
  token foo { <{$*TOP[0]}> }
}
say g.parse: 'aa' # ｢aa｣␤ 0 => ｢a｣␤ foo => ｢a｣
</code>```

So, perhaps a new variable could be introduced, one that's read only for userland code, that's bound to the overall match object during a match operation. Update See "I'm (at least half) wrong!" note above.

But then that's not only pretty ugly (unable to use a convenient short-hand back reference like $0) but refocuses attention on the need to also insert a {}. And given that it would presumably be absurdly expensive to republish all the tree of match objects after each atom, one is brought full circle back to the current status quo. Short of the fixes mentioned in this answer, I think what is currently implemented is as good as it's likely to get.

Footnotes

1 The current P6 doc doesn't use the conventional regex term "back reference" but $0, $1 etc. are numbered P6 back references. The simplest explanation I've seen of numbered back references is this SO about them using a different regex dialect. In P6 they start with $ instead of \ and are numbered starting from 0 rather than 1. The equivalent of \0 in other regex dialects is $/ in P6. In addition, $0 is an alias for $/[0], $1 for $/[1], etc.

2 One might think this would work, but it doesn't:

```<code>$_="bbaaaaawer";
/ (.) $<doesn't-work>=[$0**2..*] /;
print $<doesn't-work>.join; # Use of Nil in string context
</code>```

It seems that [...] doesn't mean "group, but don't insert a new capture level like (...) and <...> do" but instead "group, and do not capture". This renders the $<doesn't-work> in $<doesn't-work>=[$0**2..*] meaningless. Perhaps this can reasonably be fixed and perhaps it should be fixed.

3 The current "match variable" doc says:

$/ is the match variable. It stores the result of the last Regex match and so usually contains objects of type Match.

(Fwiw $/ contains a List of Match objects if an adverb like :global or :exhaustive is used.)

The above description ignores a very important use case for $/ which is its use during matching, in which case it contains the results so far of the current regex.

Following our file system analogy, $/ is like the current working directory -- let's call it "the current working match object" aka CWMO. Outside a matching operation the CWMO ($/) is ordinarily the completed result of the last regex match or grammar parse. (I say "ordinarily" because it's writable so code can change it with as little as $/ = 42.) During matching (or actions) operations the CWMO is read-only for userland code and is bound to a Match object generated by the regex/grammar engine for the current match or action rule/method.

Body:
I'm matching a sequence of a repeating arbitrary character, with a minimum length, using a perl6 regex.

After reading through https://docs.perl6.org/language/regexes#Capture_numbers and tweaking the example given, I've come up with this code using an 'external variable':

#uses an additional variable $c
perl6 -e '$_="bbaaaaawer"; /((.){} :my $c=$0; ($c)**2..*)/ && print $0';

#Output:  aaaaa

To aid in illustrating my question only, a similar regex in perl5:

#No additional variable needed
perl -e ' $_="bbaaaaawer"; /((.)\2{2,})/ && print $1';

Could someone enlighten me on the need/benefit of 'saving' $0 into $c and the requirement of the empty {}? Is there an alternative (better/golfed) perl6 regex that will match?

Thanks in advance.

Body:
Option #1: Don't sub-capture a pattern that includes a back reference

$0 is a back reference1.

If you omit the sub-capture around the expression containing $0, then the code works:

$_="bbaaaaawer"; / (.) $0**2..* / && print $/; # aaaaa

Then you can also omit the {}. (I'll return to why you sometimes need to insert a {} later in this answer.)

But perhaps you wrote a sub-capture around the expression containing the back reference because you thought you needed the sub-capture for some other later processing.

There are often other ways to do things. In your example, perhaps you wanted a way to be able to count the number of repeats. If so, you could instead write:

$_="bbaaaaawer";
/ (.) $0**2..* /;
print $/.chars div $0.chars; # 5

Job done, without the complications of the following sections.

Option #2. Sub-capture without changing the current match object during matching of the pattern that includes a back reference

Maybe you really need to sub-capture a match of an expression that includes a back reference.

This can still be done without needing to surround the $0 with a sub-capture. This saves the problems discussed in the third section below.

You can use this technique if you don't need to have sub-sub-captures of the expression and the expression isn't too complicated:

$_="bbaaaaawer";
/ (.) $<capture-when-done>=$0**2..* /;
print $<capture-when-done>.join; # aaaa

This sub-captures the result of matching the expression in a named capture but avoids inserting an additional sub-capture context around the expression (which is what causes the complications discussed in the next section).

Unfortunately, while this technique will work for the expression in your question ($0**2..*) it won't if an expression is complex enough to need grouping. This is because the syntax $<foo>=[...] doesn't work. Perhaps this is fixable without hurting performance or causing other problems.2

Option #3. Use a saved back reference inside a sub-capture

Finally we arrive at the technique you've used in your question.

Automatically available back references to sub-captures (like $0) cannot refer to sub-captures that happened outside the sub-capture they're written in. Update See "I'm (at least half) wrong!" note below.

So if, for any reason, you have to create a sub-capture (using either (...) or <...>) then you must manually store a back reference in a variable and use that instead.

Before we get to a final section explaining in detail why you must use a variable, let's first complete an initial answer to your question by covering the final wrinkle.

{} forces "publication" of match results thus far

The {} is necessary to force the :my $c=$0; to update each time it's reached using the current regex/grammar engine. If you don't write it, then the regex engine fails to update $c to a capture of 'a' and instead leaves it stuck on a capture of 'b'.

Please read "Publication" of match variables by Rakudo.

Why can't a sub-capture include a back reference to captures that happened outside that sub-capture?

First, you have to take into account that matching in P6 is optimized for the nested matching case syntactically, semantically, and implementation wise.

In particular, if, when writing a regex or grammar, you write a numbered capture (with (...)), or a named rule/capture (with <foo>), then you've inserted a new level in a tree of sub-patterns that are dynamically matched/captured at run-time.

See jnthn's answer for why and Brad's for some discussion of details.

What I'll add to those answers is a (rough!) analogy, and another discussion of why you have to use a variable and {}.

The analogy begins with a tree of sub-directories in a file system:

/
  a
  b
    c
    d

The analogy is such that:

The directory structure above corresponds to the result of a completed match operation.

After an overall match or grammar parse is complete, the match object $/ refers (analogously speaking) to the root directory.3

The sub-directories correspond to sub-captures of the match.

Numbered sub-matches/sub-captures $0 and $1 at the top level of the match operation shown below these bullet points corresponds to sub-directories a and b. The numbered sub-captures of the top level $1 sub-match/sub-capture corresponds to the c and d sub-directories.

During matching $/ refers to the "current match object" which corresponds to the "current working directory".

It's easy to refer to a sub-capture (sub-directory) of the current  match (current working directory).

It's impossible to refer to a sub-capture (sub-directory) outside the current match (current working directory) unless you've saved a reference to that outside directory (capture) or a parent of it. That is, P6 does not include an analog of .. or /! Update I'm happy to report that I'm (at least half) wrong! See What's the difference between $/ and $¢ in regex?.

If file system navigation didn't support these back references towards the root then one thing to do would be to create an environment variable that stored a particular path. That's roughly what saving a capture in a variable in a P6 regex is doing.

The central issue is that a lot of the machinery related to regexes is relative to "the current match". And this includes $/, which refers to the current match and back references like $0, which are relative to the current match. Update See "I'm (at least half) wrong!" note above.

Thus, in the following, which is runnable via tio.run here, it's easy to display 'bc' or 'c' with a code block inserted in the third pair of parens...

$_="abcd";
m/ ( ( . ) ( . ( . ) { say $/ } ( . ) ) ) /; # ｢bc｣␤ 0 => ｢c｣␤
say $/;                                      # ｢abcd｣␤ etc.

...but it's impossible to refer to the captured ｢a｣ in that third pair of parens without storing ｢a｣'s capture in a regular variable.  Update See "I'm (at least half) wrong!" note above.

Here's one way of looking at the above match:

  ↓ Start TOP level $/
m/ ( ( . ) ( . ( . ) { say $/ } ( . ) ) ) /; # captures ｢abcd｣

    ↓ Start first sub-capture; TOP's $/[0]
   (                                    )    # captures ｢abcd｣

      ↓ Start first sub-sub-capture; TOP's $/[0][0]
     ( . )                                   # captures ｢a｣

            ↓ Start *second* sub-sub-capture; TOP's $/[0][1]
           (                          )      # captures ｢bcd｣

                ↓ Start sub-sub-sub-capture; TOP's $/[0][1][0]
               ( . )                         # captures ｢c｣

                     { say $/ }              # ｢bc｣␤ 0 => ｢c｣␤

                                 ( . )       # captures 'd'

If we focus for a moment on what $/ refers to outside of the regex (and also directly inside the /.../ regex, but not inside sub-captures), then that $/ refers to the overall Match object, which ends up capturing ｢abcd｣. (In the filesystem analogy this particular $/ is the root directory.)

The $/ inside the code block inside the second sub-sub-capture refers to a lower level match object, specifically the one that, at the point the say $/ is executed, has already matched ｢bc｣ and will go on to have captured ｢bcd｣ by the end of the overall match.

But there's no built in way to refer to the sub-capture of 'a', or the overall capture (which at that point would be 'abc'), from within the sub-capture surrounding the code block. Update See "I'm (at least half) wrong!" note above.

Hence you have to do something like what you've done.

A possible improvement?

What if there were a direct analog in P6 regexes for specifying the root? Update See "I'm (at least half) wrong!" note above.

Here's an initial cut at this that might make sense. Let's define a grammar:

my $*TOP;
grammar g {
  token TOP { { $*TOP := $/ } (.) {} <foo> }
  token foo { <{$*TOP[0]}> }
}
say g.parse: 'aa' # ｢aa｣␤ 0 => ｢a｣␤ foo => ｢a｣

So, perhaps a new variable could be introduced, one that's read only for userland code, that's bound to the overall match object during a match operation. Update See "I'm (at least half) wrong!" note above.

But then that's not only pretty ugly (unable to use a convenient short-hand back reference like $0) but refocuses attention on the need to also insert a {}. And given that it would presumably be absurdly expensive to republish all the tree of match objects after each atom, one is brought full circle back to the current status quo. Short of the fixes mentioned in this answer, I think what is currently implemented is as good as it's likely to get.

Footnotes

1 The current P6 doc doesn't use the conventional regex term "back reference" but $0, $1 etc. are numbered P6 back references. The simplest explanation I've seen of numbered back references is this SO about them using a different regex dialect. In P6 they start with $ instead of \ and are numbered starting from 0 rather than 1. The equivalent of \0 in other regex dialects is $/ in P6. In addition, $0 is an alias for $/[0], $1 for $/[1], etc.

2 One might think this would work, but it doesn't:

$_="bbaaaaawer";
/ (.) $<doesn't-work>=[$0**2..*] /;
print $<doesn't-work>.join; # Use of Nil in string context

It seems that [...] doesn't mean "group, but don't insert a new capture level like (...) and <...> do" but instead "group, and do not capture". This renders the $<doesn't-work> in $<doesn't-work>=[$0**2..*] meaningless. Perhaps this can reasonably be fixed and perhaps it should be fixed.

3 The current "match variable" doc says:

$/ is the match variable. It stores the result of the last Regex match and so usually contains objects of type Match.

(Fwiw $/ contains a List of Match objects if an adverb like :global or :exhaustive is used.)

The above description ignores a very important use case for $/ which is its use during matching, in which case it contains the results so far of the current regex.

Following our file system analogy, $/ is like the current working directory -- let's call it "the current working match object" aka CWMO. Outside a matching operation the CWMO ($/) is ordinarily the completed result of the last regex match or grammar parse. (I say "ordinarily" because it's writable so code can change it with as little as $/ = 42.) During matching (or actions) operations the CWMO is read-only for userland code and is bound to a Match object generated by the regex/grammar engine for the current match or action rule/method.


问:
Eclipse shows nasty white cross in red circle with no message
This is me just trying to get rid of warning messages.

My logback xml files start rather baldly with "<configuration>..." which gives a warning about no "XML or DTD constraints".

So an answer here in SO suggests putting these two lines at the top of the file:

```<code><?XML version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
</code>```

When I do that, however, I get a nasty white cross in a red circle with no error message from Eclipse.

Can anyone identify the problem and hopefully the solution?

答:
Thought I had found an answer.

Having inserted these two lines at the top of my XML file:

```<code><?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>
</code>```

... I then found I have to position the cursor e.g. after "xml" and backspace... and then re-type the characters <?xml ... After this the nasty symbol went away.

I'm no great expert on encoding but this may be something to do with those funny "initial bytes" of a file which indicate what encoding it's using (Big-Endian, Little-Endian).

However, I then find that next time I launch Eclipse the same "no grammar constraints" warning comes back (though the white cross in red circle has gone).

Body:
This is me just trying to get rid of warning messages.

My logback xml files start rather baldly with "<configuration>..." which gives a warning about no "XML or DTD constraints".

So an answer here in SO suggests putting these two lines at the top of the file:

<?XML version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>

When I do that, however, I get a nasty white cross in a red circle with no error message from Eclipse.

Can anyone identify the problem and hopefully the solution?

Body:
Thought I had found an answer.

Having inserted these two lines at the top of my XML file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration>

... I then found I have to position the cursor e.g. after "xml" and backspace... and then re-type the characters <?xml ... After this the nasty symbol went away.

I'm no great expert on encoding but this may be something to do with those funny "initial bytes" of a file which indicate what encoding it's using (Big-Endian, Little-Endian).

However, I then find that next time I launch Eclipse the same "no grammar constraints" warning comes back (though the white cross in red circle has gone).


问:
ProGet symbols and source server: download pdb correctly but source not found
I have a problem reguarding the source files and symbols using ProGet and VS2017/VS2019.

My scenario is the following

Develop test assembly on my pc

Push mod files on our git server

Get mod files in our TeamCity (2019.1)

Build source in Release mode, pack and publish the AssemblyTest.symbols.nupkg on ProGet (5.2.3)

In VS2017 I've create a test console app, install the AssemblyTest via Package Reference and I've tried simply to press F12 on the class in my code to show the source code or step in in debug mode.

I've configure VS2017 as the guide suggests here

The nuget pack command was launched with -symbols command line parameter and the symbol.nupkg was created with the following stucture

package

service

metadata

...

lib

net472

TestAssembly.dll

TestAssembly.pdb

TestAssembly.xml

src

Properties

AssemblyInfo.cs

TestClass.cs

Pressing F12 on TestClass in my code the pdb was correctly downloaded in

c:\users\me\appdata\local\temp\symbolcache\testassembly.pdb\bf5be5cd155e4400b9b18c0e1e6a05941\testassembly.pdb

and selecting ReSharper item form the drop down list on the output window in Visual Studio I see

```<code>PdbNavigator: Downloader: http://srv.symbolsource.org/pdb/Public/testassembly.pdb/bf5be5cd155e4400b9b18c0e1e6a05941/testassembly.pdb -> The remote server returned an error: (500) Internal Server Error.
--OK, it's MS symbol server

PdbNavigator: Downloader: http://myproget/symbols/dev/testassembly.pdb/bf5be5cd155e4400b9b18c0e1e6a05941/testassembly.pdb -> ok, 15.5 KB
-- OK, it's our ProGet server

PdbNavigator: Searching for 'TestAssembly.TestClass' type sources in C:\Users\me\AppData\Local\Temp\SymbolCache\TestAssembly.pdb\bf5be5cd155e4400b9b18c0e1e6a05941\TestAssembly.pdb

PdbNavigator: Downloader: http://myproget/source-files/dev/TestAssembly/1.0.0.10/TestClass.cs -> The remote server returned an error: (404) Not Found.
-- Here we come :(

PdbNavigator: No sources found in debugging information for 'TestAssembly.TestClass' in assembly 'TestAssembly, Version=1.0.0.10, Culture=neutral, PublicKeyToken=null'
</code>```

In my symbolcache folder there is a subfolder with this path

C:\Users\me\AppData\Local\Temp\SymbolCache\src\source-files\dev\TestAssembly\1.0.0.10

but there's no source file instead.

Taking a look inside the pdb file and I've found

```<code>SRCSRV: ini ------------------------------------------------
VERSION=2
INDEXVERSION=2
VERCTRL=http
SRCSRV: variables ------------------------------------------
SRCSRVVERCTRL=http
PGSERVER=http://myproget/source-files
PGFEED=dev
PGPKGID=TestAssembly
PGPKGVER=1.0.0.10
HTTP_EXTRACT_TARGET=%pgserver%/%pgfeed%/%pgpkgid%/%pgpkgver%/%var2%
SRCSRVTRG=%http_extract_target%
SRCSRVCMD=
SRCSRV: source files ---------------------------------------
c:\buildagent\work\b5cfc05c815c43d9\testassembly\testclass.cs*TestClass.cs
SRCSRV: end ------------------------------------------------
</code>```

So, my question is: how can I download correctly the source file from ProGet?
What's wrong in my scenario?

Thank you!

Fabrizio

答:
From ProGet's perspective, a 404 is returned by the /source-files/* endpoint in any of the following cases:

the feed name (i.e. dev in your example) is not found

the feed is not a NuGet feed

the symbol server is not enabled for the feed

the package version is missing from the /source-files URL

the package version is not a valid NuGet version (1.0.0.10 looks OK)

the file itself (i.e. TestClass.cs in your example) is not found under the /src folder within the package

That being said, can you verify in the feed itself that those source files are present using the Files tab for version 1.0.0.10 of this package? I know if the normal, non-symbols package is pushed after the symbols one, it can overwrite it which effectively removes those files.

Body:
I have a problem reguarding the source files and symbols using ProGet and VS2017/VS2019.

My scenario is the following

Develop test assembly on my pc

Push mod files on our git server

Get mod files in our TeamCity (2019.1)

Build source in Release mode, pack and publish the AssemblyTest.symbols.nupkg on ProGet (5.2.3)

In VS2017 I've create a test console app, install the AssemblyTest via Package Reference and I've tried simply to press F12 on the class in my code to show the source code or step in in debug mode.

I've configure VS2017 as the guide suggests here

The nuget pack command was launched with -symbols command line parameter and the symbol.nupkg was created with the following stucture

package

service

metadata

...

lib

net472

TestAssembly.dll

TestAssembly.pdb

TestAssembly.xml

src

Properties

AssemblyInfo.cs

TestClass.cs

Pressing F12 on TestClass in my code the pdb was correctly downloaded in

c:\users\me\appdata\local\temp\symbolcache\testassembly.pdb\bf5be5cd155e4400b9b18c0e1e6a05941\testassembly.pdb

and selecting ReSharper item form the drop down list on the output window in Visual Studio I see

PdbNavigator: Downloader: http://srv.symbolsource.org/pdb/Public/testassembly.pdb/bf5be5cd155e4400b9b18c0e1e6a05941/testassembly.pdb -> The remote server returned an error: (500) Internal Server Error.
--OK, it's MS symbol server

PdbNavigator: Downloader: http://myproget/symbols/dev/testassembly.pdb/bf5be5cd155e4400b9b18c0e1e6a05941/testassembly.pdb -> ok, 15.5 KB
-- OK, it's our ProGet server

PdbNavigator: Searching for 'TestAssembly.TestClass' type sources in C:\Users\me\AppData\Local\Temp\SymbolCache\TestAssembly.pdb\bf5be5cd155e4400b9b18c0e1e6a05941\TestAssembly.pdb

PdbNavigator: Downloader: http://myproget/source-files/dev/TestAssembly/1.0.0.10/TestClass.cs -> The remote server returned an error: (404) Not Found.
-- Here we come :(

PdbNavigator: No sources found in debugging information for 'TestAssembly.TestClass' in assembly 'TestAssembly, Version=1.0.0.10, Culture=neutral, PublicKeyToken=null'

In my symbolcache folder there is a subfolder with this path

C:\Users\me\AppData\Local\Temp\SymbolCache\src\source-files\dev\TestAssembly\1.0.0.10

but there's no source file instead.

Taking a look inside the pdb file and I've found

SRCSRV: ini ------------------------------------------------
VERSION=2
INDEXVERSION=2
VERCTRL=http
SRCSRV: variables ------------------------------------------
SRCSRVVERCTRL=http
PGSERVER=http://myproget/source-files
PGFEED=dev
PGPKGID=TestAssembly
PGPKGVER=1.0.0.10
HTTP_EXTRACT_TARGET=%pgserver%/%pgfeed%/%pgpkgid%/%pgpkgver%/%var2%
SRCSRVTRG=%http_extract_target%
SRCSRVCMD=
SRCSRV: source files ---------------------------------------
c:\buildagent\work\b5cfc05c815c43d9\testassembly\testclass.cs*TestClass.cs
SRCSRV: end ------------------------------------------------

So, my question is: how can I download correctly the source file from ProGet?
What's wrong in my scenario?

Thank you!

Fabrizio


问:
Add numbers to filename
I want to store data in different files. Therefore I want to create files as follows: data_1.log, data_2.log, ..., data_N.log. The appendix .log is not necessary but would be nice. All my approaches failed so far. Here is one sample that is probably close to what I need:

```<code>#include <stdio.h>
#include <string.h>

char get_file_name(int k){
    int i, j;
    char s1[100] = "logs/data_";
    char s2[100];
    snprintf(s2, 100, "%d", k);
    for(i = 0; s1[i] != '\0'; ++i);
    for(j = 0; s2[j] != '\0'; ++j, ++i){
        s1[i] = s2[j];
    }
    s1[i] = '\0';
    return s1;
}

int main(){

    char file_name[100];
    for(int k=0; k<10; k++){
        // Get data
        // ...
        // Create filename
        strcpy(file_name, get_file_name(k));
        printf("%s", file_name);
        // fp = fopen(file_name, "w+");
        // Write data to file
        // print_results_to_file();
        // fclose(fp);
    }

    return 0;
}
</code>```

At the moment I get the following errors which I don't understand:

```<code>    string.c: In function ‘get_file_name’:
string.c:14:12: warning: returning ‘char *’ from a function with return type ‘char’ makes integer from pointer without a cast [-Wint-conversion]
     return s1;
            ^~
string.c:14:12: warning: function returns address of local variable [-Wreturn-local-addr]
string.c: In function ‘main’:
string.c:24:27: warning: passing argument 2 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion]
         strcpy(file_name, get_file_name(k));
                           ^~~~~~~~~~~~~~~~
In file included from string.c:2:
/usr/include/string.h:121:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^~~~~~
</code>```

Is there a more simpler way to create such filenames? I can't believe that there isn't one.

答:
Your errors are easily explained:

get_file_name should return a char but you create a char[] and return this(it isthe same as char*)

get_file_name returns the adress of an array that is created in the function itself. After the function ends, the array may be overwritten. Add the array as parameter or use malloc

strcpy does not work because it expects a char* (char[]) and not a char. get_file_name returns a char.

print_results_to_file is not defined. You may need to include other files you use in the program (e.g. if the function is implemented in a file func.c the prototype should be in a file called func.h that is included via #include "func.h".

Title: Add numbers to filename

Body:
I want to store data in different files. Therefore I want to create files as follows: data_1.log, data_2.log, ..., data_N.log. The appendix .log is not necessary but would be nice. All my approaches failed so far. Here is one sample that is probably close to what I need:

#include <stdio.h>
#include <string.h>

char get_file_name(int k){
    int i, j;
    char s1[100] = "logs/data_";
    char s2[100];
    snprintf(s2, 100, "%d", k);
    for(i = 0; s1[i] != '\0'; ++i);
    for(j = 0; s2[j] != '\0'; ++j, ++i){
        s1[i] = s2[j];
    }
    s1[i] = '\0';
    return s1;
}

int main(){

    char file_name[100];
    for(int k=0; k<10; k++){
        // Get data
        // ...
        // Create filename
        strcpy(file_name, get_file_name(k));
        printf("%s", file_name);
        // fp = fopen(file_name, "w+");
        // Write data to file
        // print_results_to_file();
        // fclose(fp);
    }

    return 0;
}

At the moment I get the following errors which I don't understand:

    string.c: In function ‘get_file_name’:
string.c:14:12: warning: returning ‘char *’ from a function with return type ‘char’ makes integer from pointer without a cast [-Wint-conversion]
     return s1;
            ^~
string.c:14:12: warning: function returns address of local variable [-Wreturn-local-addr]
string.c: In function ‘main’:
string.c:24:27: warning: passing argument 2 of ‘strcpy’ makes pointer from integer without a cast [-Wint-conversion]
         strcpy(file_name, get_file_name(k));
                           ^~~~~~~~~~~~~~~~
In file included from string.c:2:
/usr/include/string.h:121:14: note: expected ‘const char * restrict’ but argument is of type ‘char’
 extern char *strcpy (char *__restrict __dest, const char *__restrict __src)
              ^~~~~~

Is there a more simpler way to create such filenames? I can't believe that there isn't one.


问:
How should I think about implement the closing of an open equity position in my portfolio app?
I have a model PortStock that has a schema that looks like this:

```<code># == Schema Information
#
# Table name: port_stocks
#
#  id                :bigint(8)        not null, primary key
#  portfolio_id      :integer
#  stock_id          :integer
#  volume            :integer
#  transaction_price :float
#  current_price     :float
#  percent_change    :float
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  current_value     :float
#  dollar_change     :float
#  total_spend       :float
#  transaction_date  :datetime
#  action            :integer
#  position          :integer          default("open")
#  ticker            :string
#  slug              :string
#
</code>```

When someone buys a stock, the app creates a port_stock that has position: "open", action: :buy in their portfolio.

When they sell that position, essentially what happens is they create another port_stock but it just has position: "closed", action: :sell.

I have a few questions:

Is that really the most optimal structure? One immediate issue I see with this is that I have to close the buy position. So in essence, the full completed position would be two closed  buy and sell port_stock records. If there is only one, then the position is considered open. But does that make sense?

Should I create a method in my model to both close and open positions? I originally did this just in my controllers, but now that I am writing unit tests I don't have a clean way to close an existing open position.

Should I be approaching the buying & selling of port_stock differently?

Thoughts?

答:
The question presents two different concepts. The first concept is a "position" and the second is a "transaction". A position is the number of shares that are actually owned. This number can be positive (long) for a stock that is owned or negative (short) for stock that you've sold but must buy back at some point in time.

The position will have one or more transactions against it. Each transaction will be open, executed, or closed with related attributes such as openedOn, executedOn, and possibly closedOn for transactions that were opened but never executed.

An open transaction might represent a bid to buy shares at a particular price. But if the offer is never executed and the user chooses to cancel that transaction you will still have a record of it even though it never resulted in the purchase of shares.

With this structure, the position object only keeps track of the summary information of all completed transactions and not the transaction information making it easier to track all of the transactions that were performed against a particular position, i.e., multiple buys to accumulate shares of a stock to build a position or multiple sells to trim a position.

Body:
I have a model PortStock that has a schema that looks like this:

# == Schema Information
#
# Table name: port_stocks
#
#  id                :bigint(8)        not null, primary key
#  portfolio_id      :integer
#  stock_id          :integer
#  volume            :integer
#  transaction_price :float
#  current_price     :float
#  percent_change    :float
#  created_at        :datetime         not null
#  updated_at        :datetime         not null
#  current_value     :float
#  dollar_change     :float
#  total_spend       :float
#  transaction_date  :datetime
#  action            :integer
#  position          :integer          default("open")
#  ticker            :string
#  slug              :string
#

When someone buys a stock, the app creates a port_stock that has position: "open", action: :buy in their portfolio.

When they sell that position, essentially what happens is they create another port_stock but it just has position: "closed", action: :sell.

I have a few questions:

Is that really the most optimal structure? One immediate issue I see with this is that I have to close the buy position. So in essence, the full completed position would be two closed  buy and sell port_stock records. If there is only one, then the position is considered open. But does that make sense?

Should I create a method in my model to both close and open positions? I originally did this just in my controllers, but now that I am writing unit tests I don't have a clean way to close an existing open position.

Should I be approaching the buying & selling of port_stock differently?

Thoughts?


问:
Max function on date giving multiple records
I have got 3 tables: order, customer and invoice. I need to get the latest invoice number for each customer.

I am using the max function on order date  and then grouping by customer number and invoice number, where order status was confirmed or shipped.

```<code>  select max(o.order_date), c.customer_number, i.invoice_number
  from orders o , invoices i , customer c
  where o.order_oid = i.order_oid
  and c.customer_oid = i.customer_oid
  and o.status_oid in (  4,6)
  group by c.customer_number, i.invoice_number;
</code>```

I am getting duplicate records like:

```<code> Date       cust_num    invc#
 1/22/2018   479         I128
 4/23/2018   479         I287
 5/18/2018   479         I433
</code>```

It should have returned me only last record. What am I doing wrong?

答: You need max(invoice_number) to avoid getting a record per invoice</p>

Body:
I have got 3 tables: order, customer and invoice. I need to get the latest invoice number for each customer.

I am using the max function on order date  and then grouping by customer number and invoice number, where order status was confirmed or shipped.

  select max(o.order_date), c.customer_number, i.invoice_number
  from orders o , invoices i , customer c
  where o.order_oid = i.order_oid
  and c.customer_oid = i.customer_oid
  and o.status_oid in (  4,6)
  group by c.customer_number, i.invoice_number;

I am getting duplicate records like:

 Date       cust_num    invc#
 1/22/2018   479         I128
 4/23/2018   479         I287
 5/18/2018   479         I433

It should have returned me only last record. What am I doing wrong?


问:
ASP.NET MVC Complex Views
I have a question about complex views in ASP.NET MVC.  Where can I find good examples or best practice information on complex views and how best to create them in ASP.NET MVC.  I know the basics, but peppering the HTML with complex dynamic HTML and/or jQuery seems to be messy.

Any links to enterprise best practices or examples from experience would be appreciated.

答:
To reduce the complexity of pages I find myself developing ViewUserControls to encapsulate reusable functionality that gets included on multiple pages.  Sometimes these are generic (like a GridControl), sometimes specific (like a set of role-based menu items that gets included only when the user is authorize).  I use a master page to set up the basic outline of the page so it is common to all pages -- this includes the logon/logoff controls and menus.  Each view, then includes the other ViewUserControls that it requires via the RenderPartial HtmlHelper extension.

The other thing that I've noticed is that I'm not trying to do as much per view as I would in a WebForms application -- actions and views are more smaller and simpler than many of my old WebForms pages.  For example, I'll have a New and an Edit view, each of which includes a common ViewUserControl that contains the inputs for the form and a separate Show view that has no inputs, only spans with the contents.  The actual views will be fairly simple and contain only the differences that you would notice between the forms.  In a WebForm I would have had a templated DetailsView control and done it all in one form.

Since I'm working on my first MVC app -- it's an intranet app and not in production yet -- I can't really share a link.  I'm still learning as I go, but this seems to be the natural direction for this application anyway.  So far I haven't really found the markup to be more complex than the WebForm apps that I've developed.

OwnerDisplayName: Bart Czernicki

ContentLicense: CC BY-SA 2.5

Title: ASP.NET MVC Complex Views

OwnerDisplayName: tvanfosson


问:
How to change the background color of the iOS status bar for Safari Web Apps?
I'm trying to find a way to change the background color of the iOS status bar for a mobile web app that I'm currently working on. I've seen several solutions for native applications, but I need a solution that works for Safari and Chrome if possible.

The documentation I've been able to find shows that the following options are available:

<meta name="apple-mobile-web-app-status-bar-style" content="default">

<meta name="apple-mobile-web-app-status-bar-style" content="black">

<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

Is there a way to edit the meta tag so that the background color would be "#ff8000"?

Is there another way other than editing the meta tag to change the background color of the status bar?

Thanks for your help!

答:
Try This:

On your index.html>head tag use this:

```<code><meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
</code>```

You also need to set the:
    body { background-color: #yourcolor }
in the styles.css

It worked for me last time I tried, but remember to fill up the manifest.webmanifest with this information as well

Body:
Try This:

On your index.html>head tag use this:

<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">

You also need to set the:
    body { background-color: #yourcolor }
in the styles.css

It worked for me last time I tried, but remember to fill up the manifest.webmanifest with this information as well


问:
Fetching data from sqlite database based on timestamp of present day
In my android sqlite database there is a column that contains the timestamp in the format (2013-12-12 18:47:31) of the data. Now a  particular data may have time stamp which is earlier than present day or later than present day. e.g. today its 20 December 2013, and database contains data of 1 November 2013, 6 November 2013, 12 December 2013, 1 January 2014 etc... Now I want to fetch data which are earlier than present day i.e. 20 December 2013. How to do that?</p>

答:
I had this problem of fetching data using timestamps but to no avail after weeks i got a good solution.

set column timestamp as text on your table

```<code> public static final String CREATE_TABLE =
            "CREATE TABLE " + TABLE_NAME + "("
                    + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                    + COLUMN_INCOME + " INTEGER,"
                    + COLUMN_EXPENSE + " INTEGER,"
                    + COLUMN_TIMESTAMP + " TEXT"
                    + ")";
</code>```

get the date using new Date() and convert to string

```<code> private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }
</code>```

Insert data in your table using the getDateTime() for the timestamp

```<code>ContentValues values = new ContentValues();

        values.put(DailyTransaction.COLUMN_INCOME, income);
        values.put(DailyTransaction.COLUMN_EXPENSE, expense);
        values.put(DailyTransaction.COLUMN_TIMESTAMP, getDateTime());
</code>```

Then your sqlite query will look like this:

```<code>"SELECT * FROM "+ TABLE_NAME + " WHERE " + ClassName.COLUMN_TIMESTAMP + " <"+ "'"currentDate'";
</code>```

Body:
I had this problem of fetching data using timestamps but to no avail after weeks i got a good solution.

set column timestamp as text on your table

 public static final String CREATE_TABLE =
            "CREATE TABLE " + TABLE_NAME + "("
                    + COLUMN_ID + " INTEGER PRIMARY KEY AUTOINCREMENT,"
                    + COLUMN_INCOME + " INTEGER,"
                    + COLUMN_EXPENSE + " INTEGER,"
                    + COLUMN_TIMESTAMP + " TEXT"
                    + ")";

get the date using new Date() and convert to string

 private String getDateTime() {
        DateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy HH:mm:ss");
        Date date = new Date();
        return dateFormat.format(date);
    }

Insert data in your table using the getDateTime() for the timestamp

ContentValues values = new ContentValues();

        values.put(DailyTransaction.COLUMN_INCOME, income);
        values.put(DailyTransaction.COLUMN_EXPENSE, expense);
        values.put(DailyTransaction.COLUMN_TIMESTAMP, getDateTime());

Then your sqlite query will look like this:

"SELECT * FROM "+ TABLE_NAME + " WHERE " + ClassName.COLUMN_TIMESTAMP + " <"+ "'"currentDate'";


问:
What is the best way to get the result through Java8 function?
I need to filter elements and then sort based on certain column. Post that I would need to find the unique entries based on combination of columns. Since it is file processing, pipe(|) is used as delimiter to denote the column value.

```<code>String s1= "12|Thor|Asgaurd|1000000|Avenger|Active"
String s2= "234|Iron man|New York|9999999|Avenger|Active"
String s3= "420|Loki|Asgaurd|||Inactive"
String s4= "12|Thor|Asgaurd Bank|1000000|Avenger HQ|Active"
</code>```

Data first needs to be filtered based on the Active/Inactive status. Then it needs to be sorted based on 4th column. Lastly, the uniqueness needs to be maintained by combining column 1,2,3.

Expected Output =

```<code>"234|Iron man|New York|9999999|Avenger|Active"
"12|Thor|Asgaurd|1000000|Avenger|Active"
</code>```

答:
You can solve your task this way:

Firstly, just create POJO(Plain Old Java Object) and override the toString() method.

```<code>class MarvelPerson {

    private Integer id;
    private String name;
    private String origin;
    private Integer point = null;
    private String faction;
    private String status;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }

    public Integer getPoint() {
        return point;
    }

    public void setPoint(Integer point) {
        this.point = point;
    }

    public String getFaction() {
        return faction;
    }

    public void setFaction(String faction) {
        this.faction = faction;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(id);
        builder.append("|");
        builder.append(name);
        builder.append("|");
        builder.append(origin);
        builder.append("|");
        if(point != null) {
            builder.append(point);
        }
        builder.append("|");
        if(faction != null) {
            builder.append(faction);
        }
        builder.append("|");
        builder.append(status);

        return builder.toString();
    }
}
</code>```

Then, you should write the parser from string to MarvelPerson. Side note: Carefully, my implementation is pretty basic, and I suppose it should be modified because I may not have foreseen some corner cases.

```<code>class PersonParser {

    static MarvelPerson parse(String data) {
        MarvelPerson person = new MarvelPerson();

        String[] array = data.split("\\|", -1);

        person.setId(Integer.parseInt(array[0]));
        person.setName(array[1]);
        person.setOrigin(array[2]);

        if(!array[3].isEmpty()) {
            person.setPoint(Integer.parseInt(array[3]));
        }

        if(!array[4].isEmpty()) {
            person.setFaction(array[4]);
        }

        person.setStatus(array[5]);

        return person;
    }

}
</code>```

And then your solution:

```<code>public class Test {

    public static void main(String[] args) {
        List<MarvelPerson> list = new ArrayList<>();

        list.add(PersonParser.parse("12|Thor|Asgaurd|1000000|Avenger|Active"));
        list.add(PersonParser.parse("234|Iron man|New York|9999999|Avenger|Active"));
        list.add(PersonParser.parse("420|Loki|Asgaurd|||Inactive"));
        list.add(PersonParser.parse("12|Thor|Asgaurd Bank|1000000|Avenger HQ|Actie"));

        list.stream()
                .filter(marvelPerson -> marvelPerson.getStatus().equals("Active"))
                .sorted((o1, o2) -> o1.getPoint() <= o2.getPoint() ? 1 : -1)
                .forEach(marvelPerson -> {
                    System.out.println(marvelPerson.toString());
                });
    }

}
</code>```

The output to be printed:

234|Iron man|New York|9999999|Avenger|Active
  12|Thor|Asgaurd|1000000|Avenger|Active

Body:
I need to filter elements and then sort based on certain column. Post that I would need to find the unique entries based on combination of columns. Since it is file processing, pipe(|) is used as delimiter to denote the column value.

String s1= "12|Thor|Asgaurd|1000000|Avenger|Active"
String s2= "234|Iron man|New York|9999999|Avenger|Active"
String s3= "420|Loki|Asgaurd|||Inactive"
String s4= "12|Thor|Asgaurd Bank|1000000|Avenger HQ|Active"

Data first needs to be filtered based on the Active/Inactive status. Then it needs to be sorted based on 4th column. Lastly, the uniqueness needs to be maintained by combining column 1,2,3.

Expected Output =

"234|Iron man|New York|9999999|Avenger|Active"
"12|Thor|Asgaurd|1000000|Avenger|Active"

Body:
You can solve your task this way:

Firstly, just create POJO(Plain Old Java Object) and override the toString() method.

class MarvelPerson {

    private Integer id;
    private String name;
    private String origin;
    private Integer point = null;
    private String faction;
    private String status;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getOrigin() {
        return origin;
    }

    public void setOrigin(String origin) {
        this.origin = origin;
    }

    public Integer getPoint() {
        return point;
    }

    public void setPoint(Integer point) {
        this.point = point;
    }

    public String getFaction() {
        return faction;
    }

    public void setFaction(String faction) {
        this.faction = faction;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    @Override
    public String toString() {
        StringBuilder builder = new StringBuilder();
        builder.append(id);
        builder.append("|");
        builder.append(name);
        builder.append("|");
        builder.append(origin);
        builder.append("|");
        if(point != null) {
            builder.append(point);
        }
        builder.append("|");
        if(faction != null) {
            builder.append(faction);
        }
        builder.append("|");
        builder.append(status);

        return builder.toString();
    }
}

Then, you should write the parser from string to MarvelPerson. Side note: Carefully, my implementation is pretty basic, and I suppose it should be modified because I may not have foreseen some corner cases.

class PersonParser {

    static MarvelPerson parse(String data) {
        MarvelPerson person = new MarvelPerson();

        String[] array = data.split("\\|", -1);

        person.setId(Integer.parseInt(array[0]));
        person.setName(array[1]);
        person.setOrigin(array[2]);

        if(!array[3].isEmpty()) {
            person.setPoint(Integer.parseInt(array[3]));
        }

        if(!array[4].isEmpty()) {
            person.setFaction(array[4]);
        }

        person.setStatus(array[5]);

        return person;
    }

}

And then your solution:

public class Test {

    public static void main(String[] args) {
        List<MarvelPerson> list = new ArrayList<>();

        list.add(PersonParser.parse("12|Thor|Asgaurd|1000000|Avenger|Active"));
        list.add(PersonParser.parse("234|Iron man|New York|9999999|Avenger|Active"));
        list.add(PersonParser.parse("420|Loki|Asgaurd|||Inactive"));
        list.add(PersonParser.parse("12|Thor|Asgaurd Bank|1000000|Avenger HQ|Actie"));

        list.stream()
                .filter(marvelPerson -> marvelPerson.getStatus().equals("Active"))
                .sorted((o1, o2) -> o1.getPoint() <= o2.getPoint() ? 1 : -1)
                .forEach(marvelPerson -> {
                    System.out.println(marvelPerson.toString());
                });
    }

}

The output to be printed:

234|Iron man|New York|9999999|Avenger|Active
  12|Thor|Asgaurd|1000000|Avenger|Active


答:
From your description and comments you seem to want:

```<code>select max(o.order_date), c.customer_number,
  max(i.invoice_number) keep (dense_rank last order by o.order_date) as invoice_number
from orders o , invoices i , customer c
where o.order_oid = i.order_oid
and c.customer_oid = i.customer_oid
and o.status_oid in (  4,6)
group by c.customer_number;
</code>```

The group by no longer includes the invoice number; instead the last invoice number, based on date, is found using last.

If the invoice numbers are strictly in date order, and fixed length, you could potentially just do:

```<code>select max(o.order_date), c.customer_number, max(i.invoice_number) as invoice_number
</code>```

but if if it's possible to go from say invoice I999 to I1000 then it isn't safe to sort those just as strings, since - as a string 'I1000' will sort before 'I999'.

Not related, but you might want to consider moving to modern join syntax:

```<code>select max(o.order_date), c.customer_number,
  max(i.invoice_number) keep (dense_rank last order by o.order_date) as invoice_number
from orders o
join invoices i on i.order_oid = o.order_oid
join customer c on c.customer_oid = i.customer_oid
where o.status_oid in (4, 6)
group by c.customer_number;
</code>```

Title: Max function on date giving multiple records

Body:
From your description and comments you seem to want:

select max(o.order_date), c.customer_number,
  max(i.invoice_number) keep (dense_rank last order by o.order_date) as invoice_number
from orders o , invoices i , customer c
where o.order_oid = i.order_oid
and c.customer_oid = i.customer_oid
and o.status_oid in (  4,6)
group by c.customer_number;

The group by no longer includes the invoice number; instead the last invoice number, based on date, is found using last.

If the invoice numbers are strictly in date order, and fixed length, you could potentially just do:

select max(o.order_date), c.customer_number, max(i.invoice_number) as invoice_number

but if if it's possible to go from say invoice I999 to I1000 then it isn't safe to sort those just as strings, since - as a string 'I1000' will sort before 'I999'.

Not related, but you might want to consider moving to modern join syntax:

select max(o.order_date), c.customer_number,
  max(i.invoice_number) keep (dense_rank last order by o.order_date) as invoice_number
from orders o
join invoices i on i.order_oid = o.order_oid
join customer c on c.customer_oid = i.customer_oid
where o.status_oid in (4, 6)
group by c.customer_number;


问:
Trying to create an accordion menu and when I click on the title of the question, the answer doesn't appear or collapse, why is this?
I am trying to create an accordion  menu that allows me to make my answers hidden and only appear at the click of the question. For some reason when you click on the question nothing happens.

my code:

.accordion-Section {
  background: #fdfdfd;
  min-height: 100vh;
  padding: 10vh 0 0;
}

.accordion-Title {
  position: relative;
  margin-bottom: 45px;
  display: block;
  font-weight: 600;
  line-height: 1;
}

.accordion-Title h2::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 60px;
  height: 2px;
  background: #E91E63;
  bottom: -25px;
  margin-left: -30px;
}

.accordion-Title p {
  padding: 0 190px;
  margin-bottom: 10px;
}

.faq {
  background: #FFFFFF;
  box-shadow: 0 2px 48px 0 rgba(0, 0, 0, 0.06);
  border-radius: 4px;
}

.faq .accordion {
  border: none;
  background: none;
  border-bottom: 1px dashed #CEE1F8;
}

.faq .card .accordionCardHeader {
  padding: 0px;
  border: none;
  background: none;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
}

.faq .card .accordionCardHeader:hover {
  background: rgba(233, 30, 99, 0.1);
  padding-left: 10px;
}

.faq .card .accordionCardHeader .accordion-Title {
  width: 100%;
  text-align: left;
  padding: 0px;
  padding-left: 30px;
  padding-right: 30px;
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 1px;
  color: #3B566E;
  text-decoration: none !important;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
  cursor: pointer;
  padding-top: 20px;
  padding-bottom: 20px;
}

.faq .card .accordionCardHeader .accordion-Title .badge {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 14px;
  float: left;
  -webkit-border-radius: 100px;
  -moz-border-radius: 100px;
  border-radius: 100px;
  text-align: center;
  background: #E91E63;
  color: #fff;
  font-size: 12px;
  margin-right: 20px;
}

.faq .card .card-body {
  padding: 30px;
  padding-left: 35px;
  padding-bottom: 16px;
  font-weight: 400;
  font-size: 16px;
  color: #6F8BA4;
  line-height: 28px;
  letter-spacing: 1px;
  border-top: 1px solid #F3F8FF;
}

.faq .card .card-body p {
  margin-bottom: 14px;
}

@media (max-width: 991px) {
  .faq {
    margin-bottom: 30px;
  }
  .faq .card .accordionCardHeader .accordion-Title {
    line-height: 26px;
    margin-top: 10px;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<body>

  <section class="accordian-Section">
    <div class="container">
      <div class="row">

        <div class="col-md-6 offset-md-3">
          <div class="accordion-Title text-center pb-3">
            <h2> About </h2>
          </div>
        </div>
        <div class="col-md-6 offset-md-3">
          <div class="faq" id="accordion">
            <div class="card">
              <div class="accordionCardHeader" id="accordionHeading-1">
                <div class="mb-0">
                  <h5 class="accordion-Title" data-toggle="collapse" data-target="accordionCollapse-1" data-area-expanded="true" data-aria-controls="accordionCollapse-1">
                    <span class="badge">1</span> What is Lorem Ipsum? </h5>
                </div>
              </div>
              <div id="accordionCollapse-1" class="collapse" aria-labelledby="accordionHeading-1" data-parent="#accordion">
                <div class="card-body">
                  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
                    book. </p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

  </section>
  <script src='https://code.jquery.com/jquery-2.1.0.js'></script>
  <script src='https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js'></script>
</body></code>```

Expected: Accordion menu should appear and collapse when you click the question.

Actual: When you click on the question nothing happens.

答:
If you declare the data-target it has to be a normal CSS selector, so change data-target="accordionCollapse-1" to data-target="#accordionCollapse-1" since you try to open a div that has an id attribute.

Refer to the documentation for more info!

.accordion-Section {
  background: #fdfdfd;
  min-height: 100vh;
  padding: 10vh 0 0;
}

.accordion-Title {
  position: relative;
  margin-bottom: 45px;
  display: block;
  font-weight: 600;
  line-height: 1;
}

.accordion-Title h2::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 60px;
  height: 2px;
  background: #E91E63;
  bottom: -25px;
  margin-left: -30px;
}

.accordion-Title p {
  padding: 0 190px;
  margin-bottom: 10px;
}

.faq {
  background: #FFFFFF;
  box-shadow: 0 2px 48px 0 rgba(0, 0, 0, 0.06);
  border-radius: 4px;
}

.faq .accordion {
  border: none;
  background: none;
  border-bottom: 1px dashed #CEE1F8;
}

.faq .card .accordionCardHeader {
  padding: 0px;
  border: none;
  background: none;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
}

.faq .card .accordionCardHeader:hover {
  background: rgba(233, 30, 99, 0.1);
  padding-left: 10px;
}

.faq .card .accordionCardHeader .accordion-Title {
  width: 100%;
  text-align: left;
  padding: 0px;
  padding-left: 30px;
  padding-right: 30px;
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 1px;
  color: #3B566E;
  text-decoration: none !important;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
  cursor: pointer;
  padding-top: 20px;
  padding-bottom: 20px;
}

.faq .card .accordionCardHeader .accordion-Title .badge {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 14px;
  float: left;
  -webkit-border-radius: 100px;
  -moz-border-radius: 100px;
  border-radius: 100px;
  text-align: center;
  background: #E91E63;
  color: #fff;
  font-size: 12px;
  margin-right: 20px;
}

.faq .card .card-body {
  padding: 30px;
  padding-left: 35px;
  padding-bottom: 16px;
  font-weight: 400;
  font-size: 16px;
  color: #6F8BA4;
  line-height: 28px;
  letter-spacing: 1px;
  border-top: 1px solid #F3F8FF;
}

.faq .card .card-body p {
  margin-bottom: 14px;
}

@media (max-width: 991px) {
  .faq {
    margin-bottom: 30px;
  }
  .faq .card .accordionCardHeader .accordion-Title {
    line-height: 26px;
    margin-top: 10px;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

  <section class="accordian-Section">
    <div class="container">
      <div class="row">

        <div class="col-md-6 offset-md-3">
          <div class="accordion-Title text-center pb-3">
            <h2> About </h2>
          </div>
        </div>
        <div class="col-md-6 offset-md-3">
          <div class="faq" id="accordion">
            <div class="card">
              <div class="accordionCardHeader" id="accordionHeading-1">
                <div class="mb-0">
                  <h5 class="accordion-Title" data-toggle="collapse" data-target="#accordionCollapse-1" data-area-expanded="true" data-aria-controls="accordionCollapse-1">
                    <span class="badge">1</span> What is Lorem Ipsum? </h5>
                </div>
              </div>
              <div id="accordionCollapse-1" class="collapse" aria-labelledby="accordionHeading-1" data-parent="#accordion">
                <div class="card-body">
                  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
                    book. </p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

  </section></code>```

Also, at this moment the data-target is set to the h5 tag and not the surrounding container. To fix this you have to remove the following attributes of your h5 tag and add them to your div with the id="accordionHeading-1":

data-target="#accordionCollapse-1"

data-area-expanded="true"

data-aria-controls="accordionCollapse-1"

I also added CSS to give the box a pointer cursor:

```<code>.accordionCardHeader {
  cursor: pointer;
}
</code>```

.accordionCardHeader {
  cursor: pointer;
}

.accordion-Section {
  background: #fdfdfd;
  min-height: 100vh;
  padding: 10vh 0 0;
}

.accordion-Title {
  position: relative;
  margin-bottom: 45px;
  display: block;
  font-weight: 600;
  line-height: 1;
}

.accordion-Title h2::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 60px;
  height: 2px;
  background: #E91E63;
  bottom: -25px;
  margin-left: -30px;
}

.accordion-Title p {
  padding: 0 190px;
  margin-bottom: 10px;
}

.faq {
  background: #FFFFFF;
  box-shadow: 0 2px 48px 0 rgba(0, 0, 0, 0.06);
  border-radius: 4px;
}

.faq .accordion {
  border: none;
  background: none;
  border-bottom: 1px dashed #CEE1F8;
}

.faq .card .accordionCardHeader {
  padding: 0px;
  border: none;
  background: none;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
}

.faq .card .accordionCardHeader:hover {
  background: rgba(233, 30, 99, 0.1);
  padding-left: 10px;
}

.faq .card .accordionCardHeader .accordion-Title {
  width: 100%;
  text-align: left;
  padding: 0px;
  padding-left: 30px;
  padding-right: 30px;
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 1px;
  color: #3B566E;
  text-decoration: none !important;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
  cursor: pointer;
  padding-top: 20px;
  padding-bottom: 20px;
}

.faq .card .accordionCardHeader .accordion-Title .badge {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 14px;
  float: left;
  -webkit-border-radius: 100px;
  -moz-border-radius: 100px;
  border-radius: 100px;
  text-align: center;
  background: #E91E63;
  color: #fff;
  font-size: 12px;
  margin-right: 20px;
}

.faq .card .card-body {
  padding: 30px;
  padding-left: 35px;
  padding-bottom: 16px;
  font-weight: 400;
  font-size: 16px;
  color: #6F8BA4;
  line-height: 28px;
  letter-spacing: 1px;
  border-top: 1px solid #F3F8FF;
}

.faq .card .card-body p {
  margin-bottom: 14px;
}

@media (max-width: 991px) {
  .faq {
    margin-bottom: 30px;
  }
  .faq .card .accordionCardHeader .accordion-Title {
    line-height: 26px;
    margin-top: 10px;
  }
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<section class="accordian-Section">
  <div class="container">
    <div class="row">

      <div class="col-md-6 offset-md-3">
        <div class="accordion-Title text-center pb-3">
          <h2> About </h2>
        </div>
      </div>
      <div class="col-md-6 offset-md-3">
        <div class="faq" id="accordion">
          <div class="card">
            <div data-toggle="collapse" data-target="#accordionCollapse-1" data-area-expanded="true" data-aria-controls="accordionCollapse-1" class="accordionCardHeader" id="accordionHeading-1">
              <div class="mb-0">
                <h5 class="accordion-Title">
                  <span class="badge">1</span> What is Lorem Ipsum? </h5>
              </div>
            </div>
            <div id="accordionCollapse-1" class="collapse" aria-labelledby="accordionHeading-1" data-parent="#accordion">
              <div class="card-body">
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
                  book. </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</section></code>```

Body:
I am trying to create an accordion  menu that allows me to make my answers hidden and only appear at the click of the question. For some reason when you click on the question nothing happens.

my code:

.accordion-Section {
  background: #fdfdfd;
  min-height: 100vh;
  padding: 10vh 0 0;
}

.accordion-Title {
  position: relative;
  margin-bottom: 45px;
  display: block;
  font-weight: 600;
  line-height: 1;
}

.accordion-Title h2::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 60px;
  height: 2px;
  background: #E91E63;
  bottom: -25px;
  margin-left: -30px;
}

.accordion-Title p {
  padding: 0 190px;
  margin-bottom: 10px;
}

.faq {
  background: #FFFFFF;
  box-shadow: 0 2px 48px 0 rgba(0, 0, 0, 0.06);
  border-radius: 4px;
}

.faq .accordion {
  border: none;
  background: none;
  border-bottom: 1px dashed #CEE1F8;
}

.faq .card .accordionCardHeader {
  padding: 0px;
  border: none;
  background: none;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
}

.faq .card .accordionCardHeader:hover {
  background: rgba(233, 30, 99, 0.1);
  padding-left: 10px;
}

.faq .card .accordionCardHeader .accordion-Title {
  width: 100%;
  text-align: left;
  padding: 0px;
  padding-left: 30px;
  padding-right: 30px;
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 1px;
  color: #3B566E;
  text-decoration: none !important;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
  cursor: pointer;
  padding-top: 20px;
  padding-bottom: 20px;
}

.faq .card .accordionCardHeader .accordion-Title .badge {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 14px;
  float: left;
  -webkit-border-radius: 100px;
  -moz-border-radius: 100px;
  border-radius: 100px;
  text-align: center;
  background: #E91E63;
  color: #fff;
  font-size: 12px;
  margin-right: 20px;
}

.faq .card .card-body {
  padding: 30px;
  padding-left: 35px;
  padding-bottom: 16px;
  font-weight: 400;
  font-size: 16px;
  color: #6F8BA4;
  line-height: 28px;
  letter-spacing: 1px;
  border-top: 1px solid #F3F8FF;
}

.faq .card .card-body p {
  margin-bottom: 14px;
}

@media (max-width: 991px) {
  .faq {
    margin-bottom: 30px;
  }
  .faq .card .accordionCardHeader .accordion-Title {
    line-height: 26px;
    margin-top: 10px;
  }
}

<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

 About

                    1 What is Lorem Ipsum?

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
                    book.

Expected: Accordion menu should appear and collapse when you click the question.

Actual: When you click on the question nothing happens.

Body:
If you declare the data-target it has to be a normal CSS selector, so change data-target="accordionCollapse-1" to data-target="#accordionCollapse-1" since you try to open a div that has an id attribute.

Refer to the documentation for more info!

.accordion-Section {
  background: #fdfdfd;
  min-height: 100vh;
  padding: 10vh 0 0;
}

.accordion-Title {
  position: relative;
  margin-bottom: 45px;
  display: block;
  font-weight: 600;
  line-height: 1;
}

.accordion-Title h2::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 60px;
  height: 2px;
  background: #E91E63;
  bottom: -25px;
  margin-left: -30px;
}

.accordion-Title p {
  padding: 0 190px;
  margin-bottom: 10px;
}

.faq {
  background: #FFFFFF;
  box-shadow: 0 2px 48px 0 rgba(0, 0, 0, 0.06);
  border-radius: 4px;
}

.faq .accordion {
  border: none;
  background: none;
  border-bottom: 1px dashed #CEE1F8;
}

.faq .card .accordionCardHeader {
  padding: 0px;
  border: none;
  background: none;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
}

.faq .card .accordionCardHeader:hover {
  background: rgba(233, 30, 99, 0.1);
  padding-left: 10px;
}

.faq .card .accordionCardHeader .accordion-Title {
  width: 100%;
  text-align: left;
  padding: 0px;
  padding-left: 30px;
  padding-right: 30px;
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 1px;
  color: #3B566E;
  text-decoration: none !important;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
  cursor: pointer;
  padding-top: 20px;
  padding-bottom: 20px;
}

.faq .card .accordionCardHeader .accordion-Title .badge {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 14px;
  float: left;
  -webkit-border-radius: 100px;
  -moz-border-radius: 100px;
  border-radius: 100px;
  text-align: center;
  background: #E91E63;
  color: #fff;
  font-size: 12px;
  margin-right: 20px;
}

.faq .card .card-body {
  padding: 30px;
  padding-left: 35px;
  padding-bottom: 16px;
  font-weight: 400;
  font-size: 16px;
  color: #6F8BA4;
  line-height: 28px;
  letter-spacing: 1px;
  border-top: 1px solid #F3F8FF;
}

.faq .card .card-body p {
  margin-bottom: 14px;
}

@media (max-width: 991px) {
  .faq {
    margin-bottom: 30px;
  }
  .faq .card .accordionCardHeader .accordion-Title {
    line-height: 26px;
    margin-top: 10px;
  }
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

  <section class="accordian-Section">
    <div class="container">
      <div class="row">

        <div class="col-md-6 offset-md-3">
          <div class="accordion-Title text-center pb-3">
            <h2> About </h2>
          </div>
        </div>
        <div class="col-md-6 offset-md-3">
          <div class="faq" id="accordion">
            <div class="card">
              <div class="accordionCardHeader" id="accordionHeading-1">
                <div class="mb-0">
                  <h5 class="accordion-Title" data-toggle="collapse" data-target="#accordionCollapse-1" data-area-expanded="true" data-aria-controls="accordionCollapse-1">
                    <span class="badge">1</span> What is Lorem Ipsum? </h5>
                </div>
              </div>
              <div id="accordionCollapse-1" class="collapse" aria-labelledby="accordionHeading-1" data-parent="#accordion">
                <div class="card-body">
                  <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
                    book. </p>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

  </section>

Also, at this moment the data-target is set to the h5 tag and not the surrounding container. To fix this you have to remove the following attributes of your h5 tag and add them to your div with the id="accordionHeading-1":

data-target="#accordionCollapse-1"

data-area-expanded="true"

data-aria-controls="accordionCollapse-1"

I also added CSS to give the box a pointer cursor:

.accordionCardHeader {
  cursor: pointer;
}

.accordionCardHeader {
  cursor: pointer;
}

.accordion-Section {
  background: #fdfdfd;
  min-height: 100vh;
  padding: 10vh 0 0;
}

.accordion-Title {
  position: relative;
  margin-bottom: 45px;
  display: block;
  font-weight: 600;
  line-height: 1;
}

.accordion-Title h2::before {
  content: "";
  position: absolute;
  left: 50%;
  width: 60px;
  height: 2px;
  background: #E91E63;
  bottom: -25px;
  margin-left: -30px;
}

.accordion-Title p {
  padding: 0 190px;
  margin-bottom: 10px;
}

.faq {
  background: #FFFFFF;
  box-shadow: 0 2px 48px 0 rgba(0, 0, 0, 0.06);
  border-radius: 4px;
}

.faq .accordion {
  border: none;
  background: none;
  border-bottom: 1px dashed #CEE1F8;
}

.faq .card .accordionCardHeader {
  padding: 0px;
  border: none;
  background: none;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
}

.faq .card .accordionCardHeader:hover {
  background: rgba(233, 30, 99, 0.1);
  padding-left: 10px;
}

.faq .card .accordionCardHeader .accordion-Title {
  width: 100%;
  text-align: left;
  padding: 0px;
  padding-left: 30px;
  padding-right: 30px;
  font-weight: 400;
  font-size: 15px;
  letter-spacing: 1px;
  color: #3B566E;
  text-decoration: none !important;
  -webkit-transition: all 0.3s ease 0s;
  -moz-transition: all 0.3s ease 0s;
  -o-transition: all 0.3s ease 0s;
  transition: all 0.3s ease 0s;
  cursor: pointer;
  padding-top: 20px;
  padding-bottom: 20px;
}

.faq .card .accordionCardHeader .accordion-Title .badge {
  display: inline-block;
  width: 20px;
  height: 20px;
  line-height: 14px;
  float: left;
  -webkit-border-radius: 100px;
  -moz-border-radius: 100px;
  border-radius: 100px;
  text-align: center;
  background: #E91E63;
  color: #fff;
  font-size: 12px;
  margin-right: 20px;
}

.faq .card .card-body {
  padding: 30px;
  padding-left: 35px;
  padding-bottom: 16px;
  font-weight: 400;
  font-size: 16px;
  color: #6F8BA4;
  line-height: 28px;
  letter-spacing: 1px;
  border-top: 1px solid #F3F8FF;
}

.faq .card .card-body p {
  margin-bottom: 14px;
}

@media (max-width: 991px) {
  .faq {
    margin-bottom: 30px;
  }
  .faq .card .accordionCardHeader .accordion-Title {
    line-height: 26px;
    margin-top: 10px;
  }
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css">

<section class="accordian-Section">
  <div class="container">
    <div class="row">

      <div class="col-md-6 offset-md-3">
        <div class="accordion-Title text-center pb-3">
          <h2> About </h2>
        </div>
      </div>
      <div class="col-md-6 offset-md-3">
        <div class="faq" id="accordion">
          <div class="card">
            <div data-toggle="collapse" data-target="#accordionCollapse-1" data-area-expanded="true" data-aria-controls="accordionCollapse-1" class="accordionCardHeader" id="accordionHeading-1">
              <div class="mb-0">
                <h5 class="accordion-Title">
                  <span class="badge">1</span> What is Lorem Ipsum? </h5>
              </div>
            </div>
            <div id="accordionCollapse-1" class="collapse" aria-labelledby="accordionHeading-1" data-parent="#accordion">
              <div class="card-body">
                <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen
                  book. </p>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>

</section>


问:
Running a pass-through query without being prompted for server credentials each time
I have a pass-through query in Access that uses data from Oracle. Whenever I run the query it will give me the dialog box to enter my Oracle credentials.

Is there any ways to auto fill the ODBC log on popups?

答:
I noticed that you can save the password , only if you put the connecting string in the related parameter in properties. If you don't do it , you have to insert every time the password.

If you clic in the the query properties button, as shown in the screenshot, then you should get the prompt asking you if you want to save password.